/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ /// import { EventEmitter } from 'events'; import { CosmosDbClient } from '../client'; import { AnnotatedResponse } from '../interceptor'; import { ResolvedTaskDocument } from './document'; import { SerializedTask, TaskBase, TaskStatus } from './types'; declare interface TaskData { on(event: 'updated', listener: () => void): this; } declare class TaskData extends EventEmitter implements TaskBase { get id(): string; get type(): string; get status(): TaskStatus; get enabled(): boolean; get createTime(): Date; get nextRunTime(): Date | undefined; get lastUpdatedTime(): Date; get lastRun(): { startTime: Date; finishTime: Date; succeeded: boolean; } | undefined; get currentRunStartTime(): Date | undefined; get deliveries(): number; get attempts(): number; get runs(): number; get payload(): T; set payload(payload: T); get interval(): string | number | undefined; get lastRunTime(): Date | undefined; get document(): ResolvedTaskDocument; get ref(): string; /** * Cosmos DB client */ private _client; /** * Internally editable version of the document which represents the user's * desired document state. */ private _document; /** * A copy of the payload from the server which does not get modified by * user changes. This allows us to efficiently perform payload updates * without having to refetch the document or accidentally save changes the * user made. */ private _serverPayload?; /** * Equivalent to the server payload, but it only reflects the payload at the * last time the user updated the payload (or from initial load). This is * used to compute the patch to apply to the payload using a consistent base * rather than a server payload that has potentially changed from what the * user is working with. */ private _referencePayload; /** * Concurrency control mechanism to prevent us from trying to run multiple * updates to the same task at the same time. This will force them to * sequentialize, while still letting ligh priority requests (like lock * renewals) through in a timely manner. */ private _updateQueue; /** * We block multiple concurrent updates to the payload because it causes * weird behavior with how patches get applied to the user payload. * Generally speaking, users should either be modifying the payload OR * saving it at any point in time, not both simultaneously. */ private _updatingPayload; /** * The highest unix ms time we have seen while working with this task. We * use this to make sure that negative clock skew (i.e. our clock skews to * an earlier time) does not mess up our understanding of processing this * task. */ private _latestTime; constructor(client: CosmosDbClient, document: ResolvedTaskDocument, isComplete?: boolean); /** * Get the current unix ms time for this task. We use this instead of the * built in Date.now(), because the latter is not a monotonic clock and can * move backwards, which messes with state computations. */ timestamp(): number; /** * Saves the current payload as well as any other changes specified. * * @param changes Function producing a partial change set to update * the task data. All data but the payload may be set. * The function is called for each attempt to patch the * task with the current task state. If you want to * cancel the operation due to the current document * state, simply throw an error and it will get passed * back to you. * @param highPriority Optional boolean which will schedule this above * other requests that are pending. */ patchWithPayload(changes?: (doc: ResolvedTaskDocument) => TaskPatch, highPriority?: boolean): Promise>; /** * Applies a specific patch update to the task for system-controlled data. * * @param changes Function producing a partial change set to update * the task data. All data but the payload may be set. * The function is called for each attempt to patch the * task with the current task state. If you want to * cancel the operation due to the current document * state, simply throw an error and it will get passed * back to you. * @param highPriority Optional boolean which will schedule this above * other requests that are pending. */ patch(changes: (doc: ResolvedTaskDocument) => TaskPatch, highPriority?: boolean): Promise>; private _patchInternal; /** * Refetch the task from the database and update any data we can as * appropriate. */ sync(): Promise | undefined>>; /** * Delete the task from the database. */ delete(checkDelete?: (doc: ResolvedTaskDocument) => void): Promise>; toJSON(): SerializedTask; /** * Handle an update to the server document. * * @param doc The new server document. * @param nextReferencePayload If provided, updates the value of the * reference payload to match it so that future * payload changes will be computed against it. * This payload should be an independent copy of * the payload that is not subject to accidental * modification by the user or the system. */ private _updateDocument; /** * Apply some tweaks to the document depending on the current state. For * example, set or clear the ttl as appropriate. */ private _preProcessChange; /** * There are some scenarios (such as when a lock is lost), where some * document information is not updated correctly. We fix it up here so that * all information is represented properly, even if it's not that way on the * database. */ private _normalizeDocument; /** * Clear out any listeners and in-progress operations */ dispose(): void; } export type TaskPatch = Partial['config']>; export default TaskData; //# sourceMappingURL=data.d.ts.map