@fluidframework/task-manager 2.0.0-internal.7.0.0 → 2.0.0-internal.7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/task-manager
2
2
 
3
+ ## 2.0.0-internal.7.1.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-internal.7.0.0
4
8
 
5
9
  ### Major Changes
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-report.json"
3
+ "extends": "@fluidframework/build-common/api-extractor-base.json"
4
4
  }
@@ -0,0 +1,74 @@
1
+ ## API Report File for "@fluidframework/task-manager"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
8
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
9
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
10
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
11
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
12
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
13
+ import { ISharedObject } from '@fluidframework/shared-object-base';
14
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
15
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
16
+ import { SharedObject } from '@fluidframework/shared-object-base';
17
+
18
+ // @public
19
+ export interface ITaskManager extends ISharedObject<ITaskManagerEvents> {
20
+ abandon(taskId: string): void;
21
+ assigned(taskId: string): boolean;
22
+ canVolunteer(): boolean;
23
+ complete(taskId: string): void;
24
+ queued(taskId: string): boolean;
25
+ subscribed(taskId: string): boolean;
26
+ subscribeToTask(taskId: string): void;
27
+ volunteerForTask(taskId: string): Promise<boolean>;
28
+ }
29
+
30
+ // @public
31
+ export interface ITaskManagerEvents extends ISharedObjectEvents {
32
+ // @eventProperty
33
+ (event: "assigned", listener: TaskEventListener): any;
34
+ // @eventProperty
35
+ (event: "completed", listener: TaskEventListener): any;
36
+ // @eventProperty
37
+ (event: "lost", listener: TaskEventListener): any;
38
+ }
39
+
40
+ // @public
41
+ export type TaskEventListener = (taskId: string) => void;
42
+
43
+ // @public @sealed
44
+ export class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {
45
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
46
+ abandon(taskId: string): void;
47
+ // (undocumented)
48
+ applyStashedOp(): void;
49
+ assigned(taskId: string): boolean;
50
+ canVolunteer(): boolean;
51
+ complete(taskId: string): void;
52
+ static create(runtime: IFluidDataStoreRuntime, id?: string): TaskManager;
53
+ static getFactory(): IChannelFactory;
54
+ // @internal (undocumented)
55
+ protected initializeLocalCore(): void;
56
+ // @internal (undocumented)
57
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
58
+ // @internal (undocumented)
59
+ protected onConnect(): void;
60
+ // @internal (undocumented)
61
+ protected onDisconnect(): void;
62
+ // @internal
63
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
64
+ queued(taskId: string): boolean;
65
+ // @internal
66
+ protected reSubmitCore(): void;
67
+ subscribed(taskId: string): boolean;
68
+ subscribeToTask(taskId: string): void;
69
+ // @internal
70
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
71
+ volunteerForTask(taskId: string): Promise<boolean>;
72
+ }
73
+
74
+ ```
@@ -7,10 +7,14 @@ import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-objec
7
7
  * Describes the event listener format for {@link ITaskManagerEvents} events.
8
8
  *
9
9
  * @param taskId - The unique identifier of the related task.
10
+ *
11
+ * @public
10
12
  */
11
13
  export type TaskEventListener = (taskId: string) => void;
12
14
  /**
13
15
  * Events emitted by {@link TaskManager}.
16
+ *
17
+ * @public
14
18
  */
15
19
  export interface ITaskManagerEvents extends ISharedObjectEvents {
16
20
  /**
@@ -125,6 +129,8 @@ export interface ITaskManagerEvents extends ISharedObjectEvents {
125
129
  * when using {@link ITaskManager.subscribeToTask}.
126
130
  *
127
131
  * See {@link ITaskManagerEvents} for more details.
132
+ *
133
+ * @public
128
134
  */
129
135
  export interface ITaskManager extends ISharedObject<ITaskManagerEvents> {
130
136
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC9D;;;;;;OAMG;IACH,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,OAAE;IAEjD;;;;OAIG;IACH,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,OAAE;IAElD;;;;;;OAMG;IACH,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,OAAE;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFG;AACH,MAAM,WAAW,YAAa,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACtE;;;;;OAKG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhC;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAEpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;OAEG;IACH,YAAY,IAAI,OAAO,CAAC;CACxB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC9D;;;;;;OAMG;IACH,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,OAAE;IAEjD;;;;OAIG;IACH,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,iBAAiB,OAAE;IAElD;;;;;;OAMG;IACH,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,OAAE;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAM,WAAW,YAAa,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACtE;;;;;OAKG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhC;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAEpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;OAEG;IACH,YAAY,IAAI,OAAO,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Describes the event listener format for {@link ITaskManagerEvents} events.\n *\n * @param taskId - The unique identifier of the related task.\n */\nexport type TaskEventListener = (taskId: string) => void;\n\n/**\n * Events emitted by {@link TaskManager}.\n */\nexport interface ITaskManagerEvents extends ISharedObjectEvents {\n\t/**\n\t * Fires when a task has been exclusively assigned to the client.\n\t *\n\t * @remarks Does not account for known pending ops, but instead only reflects the current state.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"assigned\", listener: TaskEventListener);\n\n\t/**\n\t * Fires when a task the client is queued for is completed.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"completed\", listener: TaskEventListener);\n\n\t/**\n\t * Fires when the task assignment is lost by the local client.\n\t *\n\t * @remarks This could be due to the client disconnecting or by manually calling {@link ITaskManager.abandon}.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"lost\", listener: TaskEventListener);\n}\n\n/**\n * A distributed data structure that tracks queues of clients that want to exclusively run a task.\n *\n * @example Creation\n *\n * To create a {@link TaskManager}, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * @example Usage\n *\n * To volunteer for a task, use the {@link ITaskManager.volunteerForTask} method.\n * This returns a Promise that will resolve once the client has acquired exclusive rights to run the task,\n * or reject if the client is removed from the queue without acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous {@link ITaskManager.subscribeToTask}\n * method. This method does not return a value, therefore you need to rely on eventing to know when you have acquired\n * the rights to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the {@link ITaskManager.subscribed} method.\n *\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the {@link ITaskManager.abandon} method.\n * The next client in the queue will then get the rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the {@link ITaskManager.queued} and {@link ITaskManager.assigned}\n * methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the {@link ITaskManager.complete} method.\n * This will release all clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * @example Eventing\n *\n * `ITaskManager` will emit events when a task is assigned to the client, when the task assignment is lost,\n * and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using {@link ITaskManager.subscribeToTask}.\n *\n * See {@link ITaskManagerEvents} for more details.\n */\nexport interface ITaskManager extends ISharedObject<ITaskManagerEvents> {\n\t/**\n\t * Volunteer for the task. Returns a promise that resolves `true` if the task is assigned to the local client and\n\t * `false` if the task was completed by another client. It rejects if the local client abandoned the task or\n\t * disconnected while in queue.\n\t * @param taskId - Identifier for the task\n\t */\n\tvolunteerForTask(taskId: string): Promise<boolean>;\n\n\t/**\n\t * Continuously volunteer for the task. Watch the \"assigned\" event to determine if the task is assigned.\n\t * The local client will automatically re-enter the queue if it disconnects.\n\t * @param taskId - Identifier for the task\n\t */\n\tsubscribeToTask(taskId: string): void;\n\n\t/**\n\t * Exit the queue, releasing the task if currently assigned.\n\t * @param taskId - Identifier for the task\n\t */\n\tabandon(taskId: string): void;\n\n\t/**\n\t * Check whether this client is the current assignee for the task and there is no outstanding abandon op that\n\t * would abandon the assignment.\n\t * @param taskId - Identifier for the task\n\t */\n\tassigned(taskId: string): boolean;\n\n\t/**\n\t * Check whether this client is either the current assignee, in queue, or we expect they will be in queue after\n\t * outstanding ops have been ack'd.\n\t * @param taskId - Identifier for the task\n\t */\n\tqueued(taskId: string): boolean;\n\n\t/**\n\t * Check whether this client is currently subscribed to the task.\n\t * @param taskId - Identifier for the task\n\t */\n\tsubscribed(taskId: string): boolean;\n\n\t/**\n\t * Marks a task as completed and releases all clients from its queue.\n\t * @param taskId - Identifier for the task\n\t */\n\tcomplete(taskId: string): void;\n\n\t/**\n\t * Check whether this client can currently volunteer for a task.\n\t */\n\tcanVolunteer(): boolean;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Describes the event listener format for {@link ITaskManagerEvents} events.\n *\n * @param taskId - The unique identifier of the related task.\n *\n * @public\n */\nexport type TaskEventListener = (taskId: string) => void;\n\n/**\n * Events emitted by {@link TaskManager}.\n *\n * @public\n */\nexport interface ITaskManagerEvents extends ISharedObjectEvents {\n\t/**\n\t * Fires when a task has been exclusively assigned to the client.\n\t *\n\t * @remarks Does not account for known pending ops, but instead only reflects the current state.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"assigned\", listener: TaskEventListener);\n\n\t/**\n\t * Fires when a task the client is queued for is completed.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"completed\", listener: TaskEventListener);\n\n\t/**\n\t * Fires when the task assignment is lost by the local client.\n\t *\n\t * @remarks This could be due to the client disconnecting or by manually calling {@link ITaskManager.abandon}.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"lost\", listener: TaskEventListener);\n}\n\n/**\n * A distributed data structure that tracks queues of clients that want to exclusively run a task.\n *\n * @example Creation\n *\n * To create a {@link TaskManager}, call the static create method:\n *\n * ```typescript\n * const taskManager = TaskManager.create(this.runtime, id);\n * ```\n *\n * @example Usage\n *\n * To volunteer for a task, use the {@link ITaskManager.volunteerForTask} method.\n * This returns a Promise that will resolve once the client has acquired exclusive rights to run the task,\n * or reject if the client is removed from the queue without acquiring the rights.\n *\n * ```typescript\n * taskManager.volunteerForTask(\"NameOfTask\")\n * .then(() => { doTheTask(); })\n * .catch((err) => { console.error(err); });\n * ```\n *\n * Alternatively, you can indefinitely volunteer for a task with the synchronous {@link ITaskManager.subscribeToTask}\n * method. This method does not return a value, therefore you need to rely on eventing to know when you have acquired\n * the rights to run the task (see below).\n *\n * ```typescript\n * taskManager.subscribeToTask(\"NameOfTask\");\n * ```\n *\n * To check if the local client is currently subscribed to a task, use the {@link ITaskManager.subscribed} method.\n *\n * ```typescript\n * if (taskManager.subscribed(\"NameOfTask\")) {\n * console.log(\"This client is currently subscribed to the task.\");\n * }\n * ```\n *\n * To release the rights to the task, use the {@link ITaskManager.abandon} method.\n * The next client in the queue will then get the rights to run the task.\n *\n * ```typescript\n * taskManager.abandon(\"NameOfTask\");\n * ```\n *\n * To inspect your state in the queue, you can use the {@link ITaskManager.queued} and {@link ITaskManager.assigned}\n * methods.\n *\n * ```typescript\n * if (taskManager.queued(\"NameOfTask\")) {\n * console.log(\"This client is somewhere in the queue, potentially even having the task assignment.\");\n * }\n *\n * if (taskManager.assigned(\"NameOfTask\")) {\n * console.log(\"This client currently has the rights to run the task\");\n * }\n * ```\n *\n * To signal to other connected clients that a task is completed, use the {@link ITaskManager.complete} method.\n * This will release all clients from the queue and emit the \"completed\" event.\n *\n * ```typescript\n * taskManager.complete(\"NameOfTask\");\n * ```\n *\n * @example Eventing\n *\n * `ITaskManager` will emit events when a task is assigned to the client, when the task assignment is lost,\n * and when a task was completed by another client.\n *\n * ```typescript\n * taskManager.on(\"assigned\", (taskId: string) => {\n * console.log(`Client was assigned task: ${taskId}`);\n * });\n *\n * taskManager.on(\"lost\", (taskId: string) => {\n * console.log(`Client released task: ${taskId}`);\n * });\n *\n * taskManager.on(\"completed\", (taskId: string) => {\n * console.log(`Another client completed task: ${taskId}`);\n * });\n * ```\n *\n * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as\n * when using {@link ITaskManager.subscribeToTask}.\n *\n * See {@link ITaskManagerEvents} for more details.\n *\n * @public\n */\nexport interface ITaskManager extends ISharedObject<ITaskManagerEvents> {\n\t/**\n\t * Volunteer for the task. Returns a promise that resolves `true` if the task is assigned to the local client and\n\t * `false` if the task was completed by another client. It rejects if the local client abandoned the task or\n\t * disconnected while in queue.\n\t * @param taskId - Identifier for the task\n\t */\n\tvolunteerForTask(taskId: string): Promise<boolean>;\n\n\t/**\n\t * Continuously volunteer for the task. Watch the \"assigned\" event to determine if the task is assigned.\n\t * The local client will automatically re-enter the queue if it disconnects.\n\t * @param taskId - Identifier for the task\n\t */\n\tsubscribeToTask(taskId: string): void;\n\n\t/**\n\t * Exit the queue, releasing the task if currently assigned.\n\t * @param taskId - Identifier for the task\n\t */\n\tabandon(taskId: string): void;\n\n\t/**\n\t * Check whether this client is the current assignee for the task and there is no outstanding abandon op that\n\t * would abandon the assignment.\n\t * @param taskId - Identifier for the task\n\t */\n\tassigned(taskId: string): boolean;\n\n\t/**\n\t * Check whether this client is either the current assignee, in queue, or we expect they will be in queue after\n\t * outstanding ops have been ack'd.\n\t * @param taskId - Identifier for the task\n\t */\n\tqueued(taskId: string): boolean;\n\n\t/**\n\t * Check whether this client is currently subscribed to the task.\n\t * @param taskId - Identifier for the task\n\t */\n\tsubscribed(taskId: string): boolean;\n\n\t/**\n\t * Marks a task as completed and releases all clients from its queue.\n\t * @param taskId - Identifier for the task\n\t */\n\tcomplete(taskId: string): void;\n\n\t/**\n\t * Check whether this client can currently volunteer for a task.\n\t */\n\tcanVolunteer(): boolean;\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/task-manager";
8
- export declare const pkgVersion = "2.0.0-internal.7.0.0";
8
+ export declare const pkgVersion = "2.0.0-internal.7.1.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/task-manager";
11
- exports.pkgVersion = "2.0.0-internal.7.0.0";
11
+ exports.pkgVersion = "2.0.0-internal.7.1.0";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.7.0.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/task-manager\";\nexport const pkgVersion = \"2.0.0-internal.7.1.0\";\n"]}
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Contains a distributed data structure, {@link ITaskManager}, to track the queues of clients that want to
3
+ * exclusively run tasks.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
9
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
10
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
13
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
14
+ import { ISharedObject } from '@fluidframework/shared-object-base';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { SharedObject } from '@fluidframework/shared-object-base';
18
+
19
+ /**
20
+ * A distributed data structure that tracks queues of clients that want to exclusively run a task.
21
+ *
22
+ * @example Creation
23
+ *
24
+ * To create a {@link TaskManager}, call the static create method:
25
+ *
26
+ * ```typescript
27
+ * const taskManager = TaskManager.create(this.runtime, id);
28
+ * ```
29
+ *
30
+ * @example Usage
31
+ *
32
+ * To volunteer for a task, use the {@link ITaskManager.volunteerForTask} method.
33
+ * This returns a Promise that will resolve once the client has acquired exclusive rights to run the task,
34
+ * or reject if the client is removed from the queue without acquiring the rights.
35
+ *
36
+ * ```typescript
37
+ * taskManager.volunteerForTask("NameOfTask")
38
+ * .then(() => { doTheTask(); })
39
+ * .catch((err) => { console.error(err); });
40
+ * ```
41
+ *
42
+ * Alternatively, you can indefinitely volunteer for a task with the synchronous {@link ITaskManager.subscribeToTask}
43
+ * method. This method does not return a value, therefore you need to rely on eventing to know when you have acquired
44
+ * the rights to run the task (see below).
45
+ *
46
+ * ```typescript
47
+ * taskManager.subscribeToTask("NameOfTask");
48
+ * ```
49
+ *
50
+ * To check if the local client is currently subscribed to a task, use the {@link ITaskManager.subscribed} method.
51
+ *
52
+ * ```typescript
53
+ * if (taskManager.subscribed("NameOfTask")) {
54
+ * console.log("This client is currently subscribed to the task.");
55
+ * }
56
+ * ```
57
+ *
58
+ * To release the rights to the task, use the {@link ITaskManager.abandon} method.
59
+ * The next client in the queue will then get the rights to run the task.
60
+ *
61
+ * ```typescript
62
+ * taskManager.abandon("NameOfTask");
63
+ * ```
64
+ *
65
+ * To inspect your state in the queue, you can use the {@link ITaskManager.queued} and {@link ITaskManager.assigned}
66
+ * methods.
67
+ *
68
+ * ```typescript
69
+ * if (taskManager.queued("NameOfTask")) {
70
+ * console.log("This client is somewhere in the queue, potentially even having the task assignment.");
71
+ * }
72
+ *
73
+ * if (taskManager.assigned("NameOfTask")) {
74
+ * console.log("This client currently has the rights to run the task");
75
+ * }
76
+ * ```
77
+ *
78
+ * To signal to other connected clients that a task is completed, use the {@link ITaskManager.complete} method.
79
+ * This will release all clients from the queue and emit the "completed" event.
80
+ *
81
+ * ```typescript
82
+ * taskManager.complete("NameOfTask");
83
+ * ```
84
+ *
85
+ * @example Eventing
86
+ *
87
+ * `ITaskManager` will emit events when a task is assigned to the client, when the task assignment is lost,
88
+ * and when a task was completed by another client.
89
+ *
90
+ * ```typescript
91
+ * taskManager.on("assigned", (taskId: string) => {
92
+ * console.log(`Client was assigned task: ${taskId}`);
93
+ * });
94
+ *
95
+ * taskManager.on("lost", (taskId: string) => {
96
+ * console.log(`Client released task: ${taskId}`);
97
+ * });
98
+ *
99
+ * taskManager.on("completed", (taskId: string) => {
100
+ * console.log(`Another client completed task: ${taskId}`);
101
+ * });
102
+ * ```
103
+ *
104
+ * These can be useful if the logic to volunteer for a task is separated from the logic to perform the task, such as
105
+ * when using {@link ITaskManager.subscribeToTask}.
106
+ *
107
+ * See {@link ITaskManagerEvents} for more details.
108
+ *
109
+ * @public
110
+ */
111
+ export declare interface ITaskManager extends ISharedObject<ITaskManagerEvents> {
112
+ /**
113
+ * Volunteer for the task. Returns a promise that resolves `true` if the task is assigned to the local client and
114
+ * `false` if the task was completed by another client. It rejects if the local client abandoned the task or
115
+ * disconnected while in queue.
116
+ * @param taskId - Identifier for the task
117
+ */
118
+ volunteerForTask(taskId: string): Promise<boolean>;
119
+ /**
120
+ * Continuously volunteer for the task. Watch the "assigned" event to determine if the task is assigned.
121
+ * The local client will automatically re-enter the queue if it disconnects.
122
+ * @param taskId - Identifier for the task
123
+ */
124
+ subscribeToTask(taskId: string): void;
125
+ /**
126
+ * Exit the queue, releasing the task if currently assigned.
127
+ * @param taskId - Identifier for the task
128
+ */
129
+ abandon(taskId: string): void;
130
+ /**
131
+ * Check whether this client is the current assignee for the task and there is no outstanding abandon op that
132
+ * would abandon the assignment.
133
+ * @param taskId - Identifier for the task
134
+ */
135
+ assigned(taskId: string): boolean;
136
+ /**
137
+ * Check whether this client is either the current assignee, in queue, or we expect they will be in queue after
138
+ * outstanding ops have been ack'd.
139
+ * @param taskId - Identifier for the task
140
+ */
141
+ queued(taskId: string): boolean;
142
+ /**
143
+ * Check whether this client is currently subscribed to the task.
144
+ * @param taskId - Identifier for the task
145
+ */
146
+ subscribed(taskId: string): boolean;
147
+ /**
148
+ * Marks a task as completed and releases all clients from its queue.
149
+ * @param taskId - Identifier for the task
150
+ */
151
+ complete(taskId: string): void;
152
+ /**
153
+ * Check whether this client can currently volunteer for a task.
154
+ */
155
+ canVolunteer(): boolean;
156
+ }
157
+
158
+ /**
159
+ * Events emitted by {@link TaskManager}.
160
+ *
161
+ * @public
162
+ */
163
+ export declare interface ITaskManagerEvents extends ISharedObjectEvents {
164
+ /**
165
+ * Fires when a task has been exclusively assigned to the client.
166
+ *
167
+ * @remarks Does not account for known pending ops, but instead only reflects the current state.
168
+ *
169
+ * @eventProperty
170
+ */
171
+ (event: "assigned", listener: TaskEventListener): any;
172
+ /**
173
+ * Fires when a task the client is queued for is completed.
174
+ *
175
+ * @eventProperty
176
+ */
177
+ (event: "completed", listener: TaskEventListener): any;
178
+ /**
179
+ * Fires when the task assignment is lost by the local client.
180
+ *
181
+ * @remarks This could be due to the client disconnecting or by manually calling {@link ITaskManager.abandon}.
182
+ *
183
+ * @eventProperty
184
+ */
185
+ (event: "lost", listener: TaskEventListener): any;
186
+ }
187
+
188
+ /**
189
+ * Describes the event listener format for {@link ITaskManagerEvents} events.
190
+ *
191
+ * @param taskId - The unique identifier of the related task.
192
+ *
193
+ * @public
194
+ */
195
+ export declare type TaskEventListener = (taskId: string) => void;
196
+
197
+ /**
198
+ * {@inheritDoc ITaskManager}
199
+ *
200
+ * @sealed
201
+ * @public
202
+ */
203
+ export declare class TaskManager extends SharedObject<ITaskManagerEvents> implements ITaskManager {
204
+ /**
205
+ * Create a new TaskManager
206
+ *
207
+ * @param runtime - data store runtime the new task queue belongs to
208
+ * @param id - optional name of the task queue
209
+ * @returns newly create task queue (but not attached yet)
210
+ */
211
+ static create(runtime: IFluidDataStoreRuntime, id?: string): TaskManager;
212
+ /**
213
+ * Get a factory for TaskManager to register with the data store.
214
+ *
215
+ * @returns a factory that creates and load TaskManager
216
+ */
217
+ static getFactory(): IChannelFactory;
218
+ /**
219
+ * Mapping of taskId to a queue of clientIds that are waiting on the task. Maintains the consensus state of the
220
+ * queue, even if we know we've submitted an op that should eventually modify the queue.
221
+ */
222
+ private readonly taskQueues;
223
+ private readonly opWatcher;
224
+ private readonly queueWatcher;
225
+ private readonly abandonWatcher;
226
+ private readonly connectionWatcher;
227
+ private readonly completedWatcher;
228
+ private messageId;
229
+ /**
230
+ * Tracks the most recent pending op for a given task
231
+ */
232
+ private readonly latestPendingOps;
233
+ /**
234
+ * Tracks tasks that are this client is currently subscribed to.
235
+ */
236
+ private readonly subscribedTasks;
237
+ /**
238
+ * Map to track tasks that have pending complete ops.
239
+ */
240
+ private readonly pendingCompletedTasks;
241
+ /**
242
+ * Returns the clientId. Will return a placeholder if the runtime is detached and not yet assigned a clientId.
243
+ */
244
+ private get clientId();
245
+ /**
246
+ * Returns a ReadOnlyInfo object to determine current read/write permissions.
247
+ */
248
+ private get readOnlyInfo();
249
+ /**
250
+ * Constructs a new task manager. If the object is non-local an id and service interfaces will
251
+ * be provided
252
+ *
253
+ * @param runtime - data store runtime the task queue belongs to
254
+ * @param id - optional name of the task queue
255
+ */
256
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
257
+ private submitVolunteerOp;
258
+ private submitAbandonOp;
259
+ private submitCompleteOp;
260
+ /**
261
+ * {@inheritDoc ITaskManager.volunteerForTask}
262
+ */
263
+ volunteerForTask(taskId: string): Promise<boolean>;
264
+ /**
265
+ * {@inheritDoc ITaskManager.subscribeToTask}
266
+ */
267
+ subscribeToTask(taskId: string): void;
268
+ /**
269
+ * {@inheritDoc ITaskManager.abandon}
270
+ */
271
+ abandon(taskId: string): void;
272
+ /**
273
+ * {@inheritDoc ITaskManager.assigned}
274
+ */
275
+ assigned(taskId: string): boolean;
276
+ /**
277
+ * {@inheritDoc ITaskManager.queued}
278
+ */
279
+ queued(taskId: string): boolean;
280
+ /**
281
+ * {@inheritDoc ITaskManager.subscribed}
282
+ */
283
+ subscribed(taskId: string): boolean;
284
+ /**
285
+ * {@inheritDoc ITaskManager.complete}
286
+ */
287
+ complete(taskId: string): void;
288
+ /**
289
+ * {@inheritDoc ITaskManager.canVolunteer}
290
+ */
291
+ canVolunteer(): boolean;
292
+ /* Excluded from this release type: summarizeCore */
293
+ /* Excluded from this release type: loadCore */
294
+ /* Excluded from this release type: initializeLocalCore */
295
+ /* Excluded from this release type: onDisconnect */
296
+ /* Excluded from this release type: onConnect */
297
+ /* Excluded from this release type: reSubmitCore */
298
+ /* Excluded from this release type: processCore */
299
+ private addClientToQueue;
300
+ private removeClientFromQueue;
301
+ private removeClientFromAllQueues;
302
+ /**
303
+ * Will replace all instances of the placeholderClientId with the current clientId. This should only be called when
304
+ * transitioning from detached to attached and this.runtime.clientId is defined.
305
+ */
306
+ private replacePlaceholderInAllQueues;
307
+ private scrubClientsNotInQuorum;
308
+ applyStashedOp(): void;
309
+ }
310
+
311
+ export { }