@fluidframework/agent-scheduler 2.0.0-rc.1.0.4 → 2.0.0-rc.2.0.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.
Files changed (52) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +4 -1
  2. package/CHANGELOG.md +4 -0
  3. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
  4. package/api-extractor.json +1 -1
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -6
  8. package/dist/index.js.map +1 -1
  9. package/dist/package.json +3 -0
  10. package/dist/scheduler.d.ts +2 -1
  11. package/dist/scheduler.d.ts.map +1 -1
  12. package/dist/scheduler.js +2 -1
  13. package/dist/scheduler.js.map +1 -1
  14. package/dist/taskSubscription.d.ts +1 -1
  15. package/dist/taskSubscription.d.ts.map +1 -1
  16. package/dist/taskSubscription.js.map +1 -1
  17. package/dist/tsdoc-metadata.json +1 -1
  18. package/lib/{agent.d.mts → agent.d.ts} +1 -1
  19. package/lib/agent.d.ts.map +1 -0
  20. package/lib/{agent.mjs → agent.js} +1 -1
  21. package/lib/agent.js.map +1 -0
  22. package/lib/{index.d.mts → index.d.ts} +4 -4
  23. package/lib/index.d.ts.map +1 -0
  24. package/lib/index.js +8 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/{scheduler.d.mts → scheduler.d.ts} +3 -2
  27. package/lib/scheduler.d.ts.map +1 -0
  28. package/lib/{scheduler.mjs → scheduler.js} +4 -3
  29. package/lib/scheduler.js.map +1 -0
  30. package/lib/{taskSubscription.d.mts → taskSubscription.d.ts} +2 -2
  31. package/lib/taskSubscription.d.ts.map +1 -0
  32. package/lib/{taskSubscription.mjs → taskSubscription.js} +1 -1
  33. package/lib/taskSubscription.js.map +1 -0
  34. package/package.json +38 -46
  35. package/src/index.ts +3 -3
  36. package/src/scheduler.ts +11 -3
  37. package/src/taskSubscription.ts +1 -1
  38. package/tsconfig.cjs.json +7 -0
  39. package/tsconfig.json +2 -5
  40. package/lib/agent.d.mts.map +0 -1
  41. package/lib/agent.mjs.map +0 -1
  42. package/lib/index.d.mts.map +0 -1
  43. package/lib/index.mjs +0 -8
  44. package/lib/index.mjs.map +0 -1
  45. package/lib/scheduler.d.mts.map +0 -1
  46. package/lib/scheduler.mjs.map +0 -1
  47. package/lib/taskSubscription.d.mts.map +0 -1
  48. package/lib/taskSubscription.mjs.map +0 -1
  49. /package/lib/{agent-scheduler-alpha.d.mts → agent-scheduler-alpha.d.ts} +0 -0
  50. /package/lib/{agent-scheduler-beta.d.mts → agent-scheduler-beta.d.ts} +0 -0
  51. /package/lib/{agent-scheduler-public.d.mts → agent-scheduler-public.d.ts} +0 -0
  52. /package/lib/{agent-scheduler-untrimmed.d.mts → agent-scheduler-untrimmed.d.ts} +0 -0
@@ -4,7 +4,10 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
7
+ extends: [
8
+ require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
9
+ "prettier",
10
+ ],
8
11
  parserOptions: {
9
12
  project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
13
  },
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/agent-scheduler
2
2
 
3
+ ## 2.0.0-rc.2.0.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-rc.1.0.0
4
8
 
5
9
  Dependency updates only.
@@ -1,4 +1,8 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "../../../common/build/build-common/api-extractor-base-esm.json"
3
+ "extends": "../../../common/build/build-common/api-extractor-base.cjs.primary.json",
4
+ // CJS is actually secondary; so, no report.
5
+ "apiReport": {
6
+ "enabled": false
7
+ }
4
8
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "../../../common/build/build-common/api-extractor-base.json"
3
+ "extends": "../../../common/build/build-common/api-extractor-base.esm.primary.json"
4
4
  }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent";
6
- export { AgentSchedulerFactory } from "./scheduler";
7
- export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription";
5
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent.js";
6
+ export { AgentSchedulerFactory } from "./scheduler.js";
7
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -5,10 +5,10 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.TaskSubscription = exports.AgentSchedulerFactory = exports.IAgentScheduler = void 0;
8
- var agent_1 = require("./agent");
9
- Object.defineProperty(exports, "IAgentScheduler", { enumerable: true, get: function () { return agent_1.IAgentScheduler; } });
10
- var scheduler_1 = require("./scheduler");
11
- Object.defineProperty(exports, "AgentSchedulerFactory", { enumerable: true, get: function () { return scheduler_1.AgentSchedulerFactory; } });
12
- var taskSubscription_1 = require("./taskSubscription");
13
- Object.defineProperty(exports, "TaskSubscription", { enumerable: true, get: function () { return taskSubscription_1.TaskSubscription; } });
8
+ var agent_js_1 = require("./agent.js");
9
+ Object.defineProperty(exports, "IAgentScheduler", { enumerable: true, get: function () { return agent_js_1.IAgentScheduler; } });
10
+ var scheduler_js_1 = require("./scheduler.js");
11
+ Object.defineProperty(exports, "AgentSchedulerFactory", { enumerable: true, get: function () { return scheduler_js_1.AgentSchedulerFactory; } });
12
+ var taskSubscription_js_1 = require("./taskSubscription.js");
13
+ Object.defineProperty(exports, "TaskSubscription", { enumerable: true, get: function () { return taskSubscription_js_1.TaskSubscription; } });
14
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iCAAyF;AAAhF,wGAAA,eAAe,OAAA;AACxB,yCAAoD;AAA3C,kHAAA,qBAAqB,OAAA;AAC9B,uDAA+E;AAA7C,oHAAA,gBAAgB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from \"./agent\";\nexport { AgentSchedulerFactory } from \"./scheduler\";\nexport { ITaskSubscriptionEvents, TaskSubscription } from \"./taskSubscription\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uCAA4F;AAAnF,2GAAA,eAAe,OAAA;AACxB,+CAAuD;AAA9C,qHAAA,qBAAqB,OAAA;AAC9B,6DAAkF;AAAhD,uHAAA,gBAAgB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from \"./agent.js\";\nexport { AgentSchedulerFactory } from \"./scheduler.js\";\nexport { ITaskSubscriptionEvents, TaskSubscription } from \"./taskSubscription.js\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -8,7 +8,7 @@ import { FluidDataStoreRuntime } from "@fluidframework/datastore";
8
8
  import { ConsensusRegisterCollection } from "@fluidframework/register-collection";
9
9
  import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
10
10
  import { IFluidDataStoreContext, IFluidDataStoreFactory, NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
11
- import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
11
+ import { IAgentScheduler, IAgentSchedulerEvents } from "./agent.js";
12
12
  export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {
13
13
  private readonly runtime;
14
14
  private readonly context;
@@ -16,6 +16,7 @@ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEve
16
16
  static load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean): Promise<AgentScheduler>;
17
17
  get IAgentScheduler(): this;
18
18
  get IFluidLoadable(): this;
19
+ private readonly logger;
19
20
  private get clientId();
20
21
  private readonly registeredTasks;
21
22
  private readonly locallyRunnableTasks;
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAe,YAAY,EAAY,MAAM,iCAAiC,CAAC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;AA6BD;;GAEG;AACH,qBAAa,qBAAsB,YAAW,sBAAsB;IACnE,gBAAuB,IAAI,gBAAgB;IAC3C,SAAgB,IAAI,gBAA8B;IAElD,IAAW,sBAAsB,SAEhC;IAED,WAAkB,aAAa,IAAI,gCAAgC,CAElE;WAEmB,mBAAmB,CACtC,aAAa,EAAE,sBAAsB,GACnC,OAAO,CAAC,eAAe,CAAC;IAcd,oBAAoB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,OAAO,GACf,OAAO,CAAC,qBAAqB,CAAC;CASjC"}
package/dist/scheduler.js CHANGED
@@ -87,6 +87,7 @@ class AgentScheduler extends client_utils_1.TypedEventEmitter {
87
87
  // Set of registered tasks client is currently running.
88
88
  // It's subset of this.locallyRunnableTasks
89
89
  this.runningTasks = new Set();
90
+ this.logger = (0, telemetry_utils_1.createChildLogger)({ logger: runtime.logger });
90
91
  // We are expecting this class to have many listeners, so we suppress noisy "MaxListenersExceededWarning" logging.
91
92
  super.setMaxListeners(0);
92
93
  this._handle = new datastore_1.FluidObjectHandle(this, "", this.runtime.objectsRoutingContext);
@@ -350,7 +351,7 @@ class AgentScheduler extends client_utils_1.TypedEventEmitter {
350
351
  }
351
352
  }
352
353
  sendErrorEvent(eventName, error, key) {
353
- this.runtime.logger.sendErrorEvent({ eventName, key }, error);
354
+ this.logger.sendErrorEvent({ eventName, key }, error);
354
355
  }
355
356
  }
356
357
  exports.AgentScheduler = AgentScheduler;
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,2DAAoD;AAEpD,yDAImC;AACnC,iFAAoE;AACpE,6CAA2E;AAC3E,6EAAkF;AAOlF,+BAAkC;AAClC,qEAA+E;AAG/E,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAA,SAAI,GAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK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,QAAQ,CAAC,CAAC;IAChE,CAAC;;AAvCF,sDAwCC;AAvCuB,0BAAI,GAAG,YAAY,AAAf,CAAgB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { FluidObject, IFluidHandle, IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tISharedObjectRegistry,\n} from \"@fluidframework/datastore\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ISharedMap, IValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { ConsensusRegisterCollection } from \"@fluidframework/register-collection\";\nimport { IFluidDataStoreRuntime, IChannelFactory } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport { tagCodeArtifacts, UsageError } from \"@fluidframework/telemetry-utils\";\nimport { IAgentScheduler, IAgentSchedulerEvents } from \"./agent\";\n\n// Note: making sure this ID is unique and does not collide with storage provided clientID\nconst UnattachedClientId = `${uuid()}_unattached`;\n\nconst mapWait = async <T = any>(map: ISharedMap, key: string): Promise<T> => {\n\tconst maybeValue = map.get<T>(key);\n\tif (maybeValue !== undefined) {\n\t\treturn maybeValue;\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst handler = (changed: IValueChanged) => {\n\t\t\tif (changed.key === key) {\n\t\t\t\tmap.off(\"valueChanged\", handler);\n\t\t\t\tconst value = map.get<T>(changed.key);\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tthrow new Error(\"Unexpected valueChanged result\");\n\t\t\t\t}\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t};\n\t\tmap.on(\"valueChanged\", handler);\n\t});\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n\textends TypedEventEmitter<IAgentSchedulerEvents>\n\timplements IAgentScheduler\n{\n\tpublic static async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t) {\n\t\tlet root: ISharedMap;\n\t\tlet consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n\t\tif (!existing) {\n\t\t\troot = SharedMap.create(runtime, \"root\");\n\t\t\troot.bindToContext();\n\t\t\tconsensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n\t\t\tconsensusRegisterCollection.bindToContext();\n\t\t\troot.set(schedulerId, consensusRegisterCollection.handle);\n\t\t} else {\n\t\t\troot = (await runtime.getChannel(\"root\")) as ISharedMap;\n\t\t\tconst handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(\n\t\t\t\troot,\n\t\t\t\tschedulerId,\n\t\t\t);\n\t\t\tassert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n\t\t\tconsensusRegisterCollection = await handle.get();\n\t\t}\n\t\tconst agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n\t\tagentScheduler.initialize();\n\n\t\treturn agentScheduler;\n\t}\n\n\tpublic get IAgentScheduler() {\n\t\treturn this;\n\t}\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate get clientId(): string {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn UnattachedClientId;\n\t\t}\n\t\tconst clientId = this.runtime.clientId;\n\t\tassert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n\t\treturn clientId;\n\t}\n\n\t// Set of tasks registered by this client.\n\t// Has no relationship with lists below.\n\t// The only requirement here - a task can be registered by a client only once.\n\t// Other clients can pick these tasks.\n\tprivate readonly registeredTasks = new Set<string>();\n\n\t// List of all tasks client is capable of running (essentially expressed desire to run)\n\t// Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n\t// This is a strict superset of tasks running in the client.\n\tprivate readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n\t// Set of registered tasks client is currently running.\n\t// It's subset of this.locallyRunnableTasks\n\tprivate runningTasks = new Set<string>();\n\n\tprivate readonly _handle: IFluidHandle<this>;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\t\tprivate readonly context: IFluidDataStoreContext,\n\t\tprivate readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n\t) {\n\t\tsuper();\n\t\t// We are expecting this class to have many listeners, so we suppress noisy \"MaxListenersExceededWarning\" logging.\n\t\tsuper.setMaxListeners(0);\n\t\tthis._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n\t}\n\n\tpublic get handle() {\n\t\treturn this._handle;\n\t}\n\n\tpublic async register(...taskUrls: string[]): Promise<void> {\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (this.registeredTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task is already registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\tconst unregisteredTasks: string[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tthis.registeredTasks.add(taskUrl);\n\t\t\t// Only register for a new task.\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined) {\n\t\t\t\tunregisteredTasks.push(taskUrl);\n\t\t\t}\n\t\t}\n\t\treturn this.registerCore(unregisteredTasks);\n\t}\n\n\tpublic async pick(taskUrl: string, worker: () => Promise<void>): Promise<void> {\n\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\tthrow new UsageError(`Task is already attempted`, tagCodeArtifacts({ taskUrl }));\n\t\t}\n\t\tthis.locallyRunnableTasks.set(taskUrl, worker);\n\n\t\t// We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n\t\t// either perform this check proactively and call conditionally, or catch the error (in which case\n\t\t// they can know they will not get the task).\n\t\tassert(\n\t\t\tthis.context.deltaManager.clientDetails.capabilities.interactive,\n\t\t\t0x118 /* \"Bad client interactive check\" */,\n\t\t);\n\n\t\t// Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n\t\tif (this.isActive()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined || currentClient === null) {\n\t\t\t\tawait this.writeCore(taskUrl, this.clientId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async release(...taskUrls: string[]): Promise<void> {\n\t\tconst active = this.isActive();\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (!this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task was never registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\tif (!this.runningTasks.has(taskUrl)) {\n\t\t\t\t// If we got disconnected (and are attached), tasks that we WERE picked for at the time of disconnect\n\t\t\t\t// will still show us as holding the task according to getTaskClientId (the CRC is stale), but we\n\t\t\t\t// should not try to release because our disconnect will already result in either someone else or\n\t\t\t\t// ourselves clearing the task upon reconnect.\n\t\t\t\t// This UsageError is to enforce that the caller should check AgentScheduler.pickedTasks before trying\n\t\t\t\t// to release a task.\n\t\t\t\tthrow new UsageError(`Task is not currently picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\t// We may only release tasks that we KNOW we hold (detached state or connected and own the CRC). If we're\n\t\t\t// attached+disconnected then we'll lose the task automatically, and so may not release manually (someone\n\t\t\t// else might hold it by the time we reconnect)\n\t\t\tassert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n\t\t\tif (this.getTaskClientId(taskUrl) !== this.clientId) {\n\t\t\t\tthrow new UsageError(`Task was never picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\treturn this.releaseCore([...taskUrls]);\n\t}\n\n\tpublic pickedTasks(): string[] {\n\t\treturn Array.from(this.runningTasks.values());\n\t}\n\n\tprivate async registerCore(taskUrls: string[]): Promise<void> {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst registersP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tregistersP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(registersP);\n\n\t\t\t// The registers should have up to date results now. Check the status.\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tconst taskStatus = this.getTaskClientId(taskUrl);\n\n\t\t\t\t// Task should be either registered (null) or picked up.\n\t\t\t\tassert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async releaseCore(taskUrls: string[]) {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst releasesP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\t// Remove from local map so that it can be picked later.\n\t\t\t\tthis.locallyRunnableTasks.delete(taskUrl);\n\t\t\t\treleasesP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(releasesP);\n\t\t}\n\t}\n\n\tprivate async clearTasks(taskUrls: string[]) {\n\t\tassert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n\t\tconst clearP: Promise<void>[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tclearP.push(this.writeCore(taskUrl, null));\n\t\t}\n\t\tawait Promise.all(clearP);\n\t}\n\n\tprivate getTaskClientId(url: string): string | null | undefined {\n\t\treturn this.consensusRegisterCollection.read(url);\n\t}\n\n\tprivate async writeCore(key: string, clientId: string | null): Promise<void> {\n\t\tawait this.consensusRegisterCollection.write(key, clientId);\n\t}\n\n\tprivate initialize() {\n\t\tconst quorum = this.runtime.getQuorum();\n\t\t// A client left the quorum. Iterate and clear tasks held by that client.\n\t\t// Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n\t\t// Probably okay for now to have every client try to do this.\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tquorum.on(\"removeMember\", async (clientId: string) => {\n\t\t\tassert(\n\t\t\t\tthis.runtime.objectsRoutingContext.isAttached,\n\t\t\t\t0x11c /* \"Detached object routing context\" */,\n\t\t\t);\n\t\t\t// Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n\t\t\tif (this.isActive()) {\n\t\t\t\tconst tasks: Promise<any>[] = [];\n\t\t\t\tconst leftTasks: string[] = [];\n\t\t\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\t\t\tif (this.getTaskClientId(taskUrl) === clientId) {\n\t\t\t\t\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tleftTasks.push(taskUrl);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttasks.push(this.clearTasks(leftTasks));\n\t\t\t\tawait Promise.all(tasks).catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// Listeners for new/released tasks. All clients will try to grab at the same time.\n\t\t// May be we want a randomized timer (Something like raft) to reduce chattiness?\n\t\tthis.consensusRegisterCollection.on(\n\t\t\t\"atomicChanged\",\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\tasync (key: string, currentClient: string | null) => {\n\t\t\t\t// Check if this client was chosen.\n\t\t\t\tif (this.isActive() && currentClient === this.clientId) {\n\t\t\t\t\tthis.onNewTaskAssigned(key);\n\t\t\t\t} else {\n\t\t\t\t\t// The call below mutates the consensusRegisterCollection in\n\t\t\t\t\t// its event handler, which is not safe.\n\t\t\t\t\t// We need to force this to be part of a different batch of ops by\n\t\t\t\t\t// scheduling a microtask in order to work around the current validations.\n\t\t\t\t\t// This is not recommended and should be avoided.\n\t\t\t\t\tawait Promise.resolve().then(async () => {\n\t\t\t\t\t\tawait this.onTaskReassigned(key, currentClient);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tif (this.isActive()) {\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tthis.runtime.on(\"connected\", () => {\n\t\t\tif (this.isActive()) {\n\t\t\t\tthis.initializeCore();\n\t\t\t}\n\t\t});\n\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tthis.runtime\n\t\t\t\t.waitAttached()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.clearRunningTasks();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n\t\t\t\t});\n\t\t}\n\n\t\tthis.runtime.on(\"disconnected\", () => {\n\t\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t\tthis.clearRunningTasks();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate onNewTaskAssigned(key: string) {\n\t\tassert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n\t\tthis.runningTasks.add(key);\n\t\tconst worker = this.locallyRunnableTasks.get(key);\n\t\tif (worker === undefined) {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n\t\t} else {\n\t\t\tthis.emit(\"picked\", key);\n\t\t\tworker().catch((error) => {\n\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async onTaskReassigned(key: string, currentClient: string | null) {\n\t\tif (this.runningTasks.has(key)) {\n\t\t\tthis.runningTasks.delete(key);\n\t\t\tthis.emit(\"released\", key);\n\t\t}\n\t\tassert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n\t\tif (this.isActive()) {\n\t\t\t// attempt to pick up task if we are connected.\n\t\t\t// If not, initializeCore() will do it when connected\n\t\t\tif (currentClient === null) {\n\t\t\t\tif (this.locallyRunnableTasks.has(key)) {\n\t\t\t\t\tawait this.writeCore(key, this.clientId);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the op came from dropped client\n\t\t\t// This could happen when \"old\" ops are submitted on reconnection.\n\t\t\t// They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n\t\t\telse if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tawait this.writeCore(key, null);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isActive() {\n\t\t// Scheduler should be active in detached container.\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!this.runtime.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n\t\t// here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n\t\treturn this.context.deltaManager.active;\n\t}\n\n\tprivate initializeCore() {\n\t\t// Nobody released the tasks held by last client in previous session.\n\t\t// Check to see if this client needs to do this.\n\t\tconst clearCandidates: string[] = [];\n\t\tconst tasks: Promise<any>[] = [];\n\n\t\tfor (const [taskUrl] of this.locallyRunnableTasks) {\n\t\t\tif (!this.getTaskClientId(taskUrl)) {\n\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tclearCandidates.push(taskUrl);\n\t\t\t}\n\t\t}\n\n\t\ttasks.push(this.clearTasks(clearCandidates));\n\n\t\tPromise.all(tasks).catch((error) => {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_InitError\", error);\n\t\t});\n\t}\n\n\tprivate clearRunningTasks() {\n\t\tconst tasks = this.runningTasks;\n\t\tthis.runningTasks = new Set<string>();\n\n\t\tif (this.isActive()) {\n\t\t\t// Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n\t\t\t// If we are simply disconnected, then proper cleanup will be done on connection.\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tfor (const task of tasks) {\n\t\t\tthis.emit(\"lost\", task);\n\t\t}\n\t}\n\n\tprivate sendErrorEvent(eventName: string, error: any, key?: string) {\n\t\tthis.runtime.logger.sendErrorEvent({ eventName, key }, error);\n\t}\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n\tconstructor(\n\t\tdataStoreContext: IFluidDataStoreContext,\n\t\tsharedObjectRegistry: ISharedObjectRegistry,\n\t\texisting: boolean,\n\t) {\n\t\tsuper(dataStoreContext, sharedObjectRegistry, existing, async () =>\n\t\t\tAgentScheduler.load(this, dataStoreContext, existing),\n\t\t);\n\t}\n\tpublic async request(request: IRequest) {\n\t\tconst response = await super.request(request);\n\t\tif (response.status === 404) {\n\t\t\tif (request.url === \"\" || request.url === \"/\") {\n\t\t\t\tconst agentScheduler = await this.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tagentScheduler !== undefined,\n\t\t\t\t\t0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */,\n\t\t\t\t);\n\n\t\t\t\treturn { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n\t\t\t}\n\t\t}\n\t\treturn response;\n\t}\n}\n\n/**\n * @alpha\n */\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n\tpublic static readonly type = \"_scheduler\";\n\tpublic readonly type = AgentSchedulerFactory.type;\n\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\tpublic static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(new AgentSchedulerFactory())];\n\t}\n\n\tpublic static async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t): Promise<IAgentScheduler> {\n\t\tconst packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n\t\tconst dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n\t\tconst entryPoint: FluidObject<IAgentScheduler> = await dataStore.entryPoint.get();\n\n\t\t// AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n\t\t// while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n\t\tassert(\n\t\t\tentryPoint.IAgentScheduler !== undefined,\n\t\t\t0x467 /* The data store's entryPoint is not an AgentScheduler! */,\n\t\t);\n\t\treturn entryPoint as unknown as AgentScheduler;\n\t}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst mapFactory = SharedMap.getFactory();\n\t\tconst consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\t\tdataTypes.set(mapFactory.type, mapFactory);\n\t\tdataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n\t\treturn new AgentSchedulerRuntime(context, dataTypes, existing);\n\t}\n}\n"]}
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,2DAAoD;AAEpD,yDAImC;AACnC,iFAAoE;AACpE,6CAA2E;AAC3E,6EAAkF;AAOlF,+BAAkC;AAClC,qEAKyC;AAGzC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAA,SAAI,GAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,EAAW,GAAe,EAAE,GAAW,EAAc,EAAE;IAC3E,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;IACnC,IAAI,UAAU,KAAK,SAAS,EAAE;QAC7B,OAAO,UAAU,CAAC;KAClB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,CAAC,OAAsB,EAAE,EAA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,CAAC;IACb,CAAC;IAEM,MAAM,KAAK,aAAa;QAC9B,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,mBAAmB,CACtC,aAAqC;QAErC,MAAM,WAAW,GAAG,CAAC,GAAG,aAAa,CAAC,WAAW,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/E,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,UAAU,GAAiC,MAAM,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;QAElF,8GAA8G;QAC9G,6FAA6F;QAC7F,IAAA,mBAAM,EACL,UAAU,CAAC,eAAe,KAAK,SAAS,EACxC,KAAK,CAAC,2DAA2D,CACjE,CAAC;QACF,OAAO,UAAuC,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAChC,OAA+B,EAC/B,QAAiB;QAEjB,MAAM,UAAU,GAAG,eAAS,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,kCAAkC,GAAG,iDAA2B,CAAC,UAAU,EAAE,CAAC;QACpF,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;QACrD,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3C,SAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,IAAI,EAAE,kCAAkC,CAAC,CAAC;QAE3F,OAAO,IAAI,qBAAqB,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;;AAvCF,sDAwCC;AAvCuB,0BAAI,GAAG,YAAY,AAAf,CAAgB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { FluidObject, IFluidHandle, IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tISharedObjectRegistry,\n} from \"@fluidframework/datastore\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ISharedMap, IValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { ConsensusRegisterCollection } from \"@fluidframework/register-collection\";\nimport { IFluidDataStoreRuntime, IChannelFactory } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\tcreateChildLogger,\n\ttagCodeArtifacts,\n\tUsageError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils\";\nimport { IAgentScheduler, IAgentSchedulerEvents } from \"./agent.js\";\n\n// Note: making sure this ID is unique and does not collide with storage provided clientID\nconst UnattachedClientId = `${uuid()}_unattached`;\n\nconst mapWait = async <T = any>(map: ISharedMap, key: string): Promise<T> => {\n\tconst maybeValue = map.get<T>(key);\n\tif (maybeValue !== undefined) {\n\t\treturn maybeValue;\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst handler = (changed: IValueChanged) => {\n\t\t\tif (changed.key === key) {\n\t\t\t\tmap.off(\"valueChanged\", handler);\n\t\t\t\tconst value = map.get<T>(changed.key);\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tthrow new Error(\"Unexpected valueChanged result\");\n\t\t\t\t}\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t};\n\t\tmap.on(\"valueChanged\", handler);\n\t});\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n\textends TypedEventEmitter<IAgentSchedulerEvents>\n\timplements IAgentScheduler\n{\n\tpublic static async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t) {\n\t\tlet root: ISharedMap;\n\t\tlet consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n\t\tif (!existing) {\n\t\t\troot = SharedMap.create(runtime, \"root\");\n\t\t\troot.bindToContext();\n\t\t\tconsensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n\t\t\tconsensusRegisterCollection.bindToContext();\n\t\t\troot.set(schedulerId, consensusRegisterCollection.handle);\n\t\t} else {\n\t\t\troot = (await runtime.getChannel(\"root\")) as ISharedMap;\n\t\t\tconst handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(\n\t\t\t\troot,\n\t\t\t\tschedulerId,\n\t\t\t);\n\t\t\tassert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n\t\t\tconsensusRegisterCollection = await handle.get();\n\t\t}\n\t\tconst agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n\t\tagentScheduler.initialize();\n\n\t\treturn agentScheduler;\n\t}\n\n\tpublic get IAgentScheduler() {\n\t\treturn this;\n\t}\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate get clientId(): string {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn UnattachedClientId;\n\t\t}\n\t\tconst clientId = this.runtime.clientId;\n\t\tassert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n\t\treturn clientId;\n\t}\n\n\t// Set of tasks registered by this client.\n\t// Has no relationship with lists below.\n\t// The only requirement here - a task can be registered by a client only once.\n\t// Other clients can pick these tasks.\n\tprivate readonly registeredTasks = new Set<string>();\n\n\t// List of all tasks client is capable of running (essentially expressed desire to run)\n\t// Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n\t// This is a strict superset of tasks running in the client.\n\tprivate readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n\t// Set of registered tasks client is currently running.\n\t// It's subset of this.locallyRunnableTasks\n\tprivate runningTasks = new Set<string>();\n\n\tprivate readonly _handle: IFluidHandle<this>;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\t\tprivate readonly context: IFluidDataStoreContext,\n\t\tprivate readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger: runtime.logger });\n\t\t// We are expecting this class to have many listeners, so we suppress noisy \"MaxListenersExceededWarning\" logging.\n\t\tsuper.setMaxListeners(0);\n\t\tthis._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n\t}\n\n\tpublic get handle() {\n\t\treturn this._handle;\n\t}\n\n\tpublic async register(...taskUrls: string[]): Promise<void> {\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (this.registeredTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task is already registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\tconst unregisteredTasks: string[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tthis.registeredTasks.add(taskUrl);\n\t\t\t// Only register for a new task.\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined) {\n\t\t\t\tunregisteredTasks.push(taskUrl);\n\t\t\t}\n\t\t}\n\t\treturn this.registerCore(unregisteredTasks);\n\t}\n\n\tpublic async pick(taskUrl: string, worker: () => Promise<void>): Promise<void> {\n\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\tthrow new UsageError(`Task is already attempted`, tagCodeArtifacts({ taskUrl }));\n\t\t}\n\t\tthis.locallyRunnableTasks.set(taskUrl, worker);\n\n\t\t// We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n\t\t// either perform this check proactively and call conditionally, or catch the error (in which case\n\t\t// they can know they will not get the task).\n\t\tassert(\n\t\t\tthis.context.deltaManager.clientDetails.capabilities.interactive,\n\t\t\t0x118 /* \"Bad client interactive check\" */,\n\t\t);\n\n\t\t// Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n\t\tif (this.isActive()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined || currentClient === null) {\n\t\t\t\tawait this.writeCore(taskUrl, this.clientId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async release(...taskUrls: string[]): Promise<void> {\n\t\tconst active = this.isActive();\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (!this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task was never registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\tif (!this.runningTasks.has(taskUrl)) {\n\t\t\t\t// If we got disconnected (and are attached), tasks that we WERE picked for at the time of disconnect\n\t\t\t\t// will still show us as holding the task according to getTaskClientId (the CRC is stale), but we\n\t\t\t\t// should not try to release because our disconnect will already result in either someone else or\n\t\t\t\t// ourselves clearing the task upon reconnect.\n\t\t\t\t// This UsageError is to enforce that the caller should check AgentScheduler.pickedTasks before trying\n\t\t\t\t// to release a task.\n\t\t\t\tthrow new UsageError(`Task is not currently picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\t// We may only release tasks that we KNOW we hold (detached state or connected and own the CRC). If we're\n\t\t\t// attached+disconnected then we'll lose the task automatically, and so may not release manually (someone\n\t\t\t// else might hold it by the time we reconnect)\n\t\t\tassert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n\t\t\tif (this.getTaskClientId(taskUrl) !== this.clientId) {\n\t\t\t\tthrow new UsageError(`Task was never picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\treturn this.releaseCore([...taskUrls]);\n\t}\n\n\tpublic pickedTasks(): string[] {\n\t\treturn Array.from(this.runningTasks.values());\n\t}\n\n\tprivate async registerCore(taskUrls: string[]): Promise<void> {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst registersP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tregistersP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(registersP);\n\n\t\t\t// The registers should have up to date results now. Check the status.\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tconst taskStatus = this.getTaskClientId(taskUrl);\n\n\t\t\t\t// Task should be either registered (null) or picked up.\n\t\t\t\tassert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async releaseCore(taskUrls: string[]) {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst releasesP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\t// Remove from local map so that it can be picked later.\n\t\t\t\tthis.locallyRunnableTasks.delete(taskUrl);\n\t\t\t\treleasesP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(releasesP);\n\t\t}\n\t}\n\n\tprivate async clearTasks(taskUrls: string[]) {\n\t\tassert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n\t\tconst clearP: Promise<void>[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tclearP.push(this.writeCore(taskUrl, null));\n\t\t}\n\t\tawait Promise.all(clearP);\n\t}\n\n\tprivate getTaskClientId(url: string): string | null | undefined {\n\t\treturn this.consensusRegisterCollection.read(url);\n\t}\n\n\tprivate async writeCore(key: string, clientId: string | null): Promise<void> {\n\t\tawait this.consensusRegisterCollection.write(key, clientId);\n\t}\n\n\tprivate initialize() {\n\t\tconst quorum = this.runtime.getQuorum();\n\t\t// A client left the quorum. Iterate and clear tasks held by that client.\n\t\t// Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n\t\t// Probably okay for now to have every client try to do this.\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tquorum.on(\"removeMember\", async (clientId: string) => {\n\t\t\tassert(\n\t\t\t\tthis.runtime.objectsRoutingContext.isAttached,\n\t\t\t\t0x11c /* \"Detached object routing context\" */,\n\t\t\t);\n\t\t\t// Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n\t\t\tif (this.isActive()) {\n\t\t\t\tconst tasks: Promise<any>[] = [];\n\t\t\t\tconst leftTasks: string[] = [];\n\t\t\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\t\t\tif (this.getTaskClientId(taskUrl) === clientId) {\n\t\t\t\t\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tleftTasks.push(taskUrl);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttasks.push(this.clearTasks(leftTasks));\n\t\t\t\tawait Promise.all(tasks).catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// Listeners for new/released tasks. All clients will try to grab at the same time.\n\t\t// May be we want a randomized timer (Something like raft) to reduce chattiness?\n\t\tthis.consensusRegisterCollection.on(\n\t\t\t\"atomicChanged\",\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\tasync (key: string, currentClient: string | null) => {\n\t\t\t\t// Check if this client was chosen.\n\t\t\t\tif (this.isActive() && currentClient === this.clientId) {\n\t\t\t\t\tthis.onNewTaskAssigned(key);\n\t\t\t\t} else {\n\t\t\t\t\t// The call below mutates the consensusRegisterCollection in\n\t\t\t\t\t// its event handler, which is not safe.\n\t\t\t\t\t// We need to force this to be part of a different batch of ops by\n\t\t\t\t\t// scheduling a microtask in order to work around the current validations.\n\t\t\t\t\t// This is not recommended and should be avoided.\n\t\t\t\t\tawait Promise.resolve().then(async () => {\n\t\t\t\t\t\tawait this.onTaskReassigned(key, currentClient);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tif (this.isActive()) {\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tthis.runtime.on(\"connected\", () => {\n\t\t\tif (this.isActive()) {\n\t\t\t\tthis.initializeCore();\n\t\t\t}\n\t\t});\n\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tthis.runtime\n\t\t\t\t.waitAttached()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.clearRunningTasks();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n\t\t\t\t});\n\t\t}\n\n\t\tthis.runtime.on(\"disconnected\", () => {\n\t\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t\tthis.clearRunningTasks();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate onNewTaskAssigned(key: string) {\n\t\tassert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n\t\tthis.runningTasks.add(key);\n\t\tconst worker = this.locallyRunnableTasks.get(key);\n\t\tif (worker === undefined) {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n\t\t} else {\n\t\t\tthis.emit(\"picked\", key);\n\t\t\tworker().catch((error) => {\n\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async onTaskReassigned(key: string, currentClient: string | null) {\n\t\tif (this.runningTasks.has(key)) {\n\t\t\tthis.runningTasks.delete(key);\n\t\t\tthis.emit(\"released\", key);\n\t\t}\n\t\tassert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n\t\tif (this.isActive()) {\n\t\t\t// attempt to pick up task if we are connected.\n\t\t\t// If not, initializeCore() will do it when connected\n\t\t\tif (currentClient === null) {\n\t\t\t\tif (this.locallyRunnableTasks.has(key)) {\n\t\t\t\t\tawait this.writeCore(key, this.clientId);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the op came from dropped client\n\t\t\t// This could happen when \"old\" ops are submitted on reconnection.\n\t\t\t// They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n\t\t\telse if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tawait this.writeCore(key, null);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isActive() {\n\t\t// Scheduler should be active in detached container.\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!this.runtime.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n\t\t// here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n\t\treturn this.context.deltaManager.active;\n\t}\n\n\tprivate initializeCore() {\n\t\t// Nobody released the tasks held by last client in previous session.\n\t\t// Check to see if this client needs to do this.\n\t\tconst clearCandidates: string[] = [];\n\t\tconst tasks: Promise<any>[] = [];\n\n\t\tfor (const [taskUrl] of this.locallyRunnableTasks) {\n\t\t\tif (!this.getTaskClientId(taskUrl)) {\n\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tclearCandidates.push(taskUrl);\n\t\t\t}\n\t\t}\n\n\t\ttasks.push(this.clearTasks(clearCandidates));\n\n\t\tPromise.all(tasks).catch((error) => {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_InitError\", error);\n\t\t});\n\t}\n\n\tprivate clearRunningTasks() {\n\t\tconst tasks = this.runningTasks;\n\t\tthis.runningTasks = new Set<string>();\n\n\t\tif (this.isActive()) {\n\t\t\t// Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n\t\t\t// If we are simply disconnected, then proper cleanup will be done on connection.\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tfor (const task of tasks) {\n\t\t\tthis.emit(\"lost\", task);\n\t\t}\n\t}\n\n\tprivate sendErrorEvent(eventName: string, error: any, key?: string) {\n\t\tthis.logger.sendErrorEvent({ eventName, key }, error);\n\t}\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n\tconstructor(\n\t\tdataStoreContext: IFluidDataStoreContext,\n\t\tsharedObjectRegistry: ISharedObjectRegistry,\n\t\texisting: boolean,\n\t) {\n\t\tsuper(dataStoreContext, sharedObjectRegistry, existing, async () =>\n\t\t\tAgentScheduler.load(this, dataStoreContext, existing),\n\t\t);\n\t}\n\tpublic async request(request: IRequest) {\n\t\tconst response = await super.request(request);\n\t\tif (response.status === 404) {\n\t\t\tif (request.url === \"\" || request.url === \"/\") {\n\t\t\t\tconst agentScheduler = await this.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tagentScheduler !== undefined,\n\t\t\t\t\t0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */,\n\t\t\t\t);\n\n\t\t\t\treturn { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n\t\t\t}\n\t\t}\n\t\treturn response;\n\t}\n}\n\n/**\n * @alpha\n */\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n\tpublic static readonly type = \"_scheduler\";\n\tpublic readonly type = AgentSchedulerFactory.type;\n\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\tpublic static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(new AgentSchedulerFactory())];\n\t}\n\n\tpublic static async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t): Promise<IAgentScheduler> {\n\t\tconst packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n\t\tconst dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n\t\tconst entryPoint: FluidObject<IAgentScheduler> = await dataStore.entryPoint.get();\n\n\t\t// AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n\t\t// while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n\t\tassert(\n\t\t\tentryPoint.IAgentScheduler !== undefined,\n\t\t\t0x467 /* The data store's entryPoint is not an AgentScheduler! */,\n\t\t);\n\t\treturn entryPoint as unknown as AgentScheduler;\n\t}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst mapFactory = SharedMap.getFactory();\n\t\tconst consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\t\tdataTypes.set(mapFactory.type, mapFactory);\n\t\tdataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n\t\treturn new AgentSchedulerRuntime(context, dataTypes, existing);\n\t}\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { IEvent } from "@fluidframework/core-interfaces";
6
6
  import { TypedEventEmitter } from "@fluid-internal/client-utils";
7
- import { IAgentScheduler } from "./agent";
7
+ import { IAgentScheduler } from "./agent.js";
8
8
  /**
9
9
  * Events emitted by {@link TaskSubscription}.
10
10
  * @alpha
@@ -1 +1 @@
1
- {"version":3,"file":"taskSubscription.d.ts","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,MAAM;IACtD,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CACtD;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,uBAAuB,CAAC;IAQ9E,OAAO,CAAC,QAAQ,CAAC,cAAc;aACf,MAAM,EAAE,MAAM;IAR/B,OAAO,CAAC,UAAU,CAAkB;IAEpC;;;OAGG;gBAEe,cAAc,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM;IAoB/B;;;OAGG;IACI,QAAQ;IAIf;;;OAGG;IACI,SAAS;CAUhB"}
1
+ {"version":3,"file":"taskSubscription.d.ts","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,MAAM;IACtD,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CACtD;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,uBAAuB,CAAC;IAQ9E,OAAO,CAAC,QAAQ,CAAC,cAAc;aACf,MAAM,EAAE,MAAM;IAR/B,OAAO,CAAC,UAAU,CAAkB;IAEpC;;;OAGG;gBAEe,cAAc,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM;IAoB/B;;;OAGG;IACI,QAAQ;IAIf;;;OAGG;IACI,SAAS;CAUhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"taskSubscription.js","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAiE;AAWjE;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,gCAA0C;IAG/E;;;OAGG;IACH,YACkB,cAA+B,EAChC,MAAc;QAE9B,KAAK,EAAE,CAAC;QAHS,mBAAc,GAAd,cAAc,CAAiB;QAChC,WAAM,GAAN,MAAM,CAAQ;QARvB,eAAU,GAAY,KAAK,CAAC;QAWnC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAe,EAAE,EAAE;YAC/C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACrB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,OAAe,EAAE,EAAE;YACjD,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YAC7C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,uFAAuF;YACvF,gFAAgF;YAChF,0FAA0F;YAC1F,qCAAqC;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACvB;IACF,CAAC;CACD;AAnDD,4CAmDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IAgentScheduler } from \"./agent\";\n\n/**\n * Events emitted by {@link TaskSubscription}.\n * @alpha\n */\nexport interface ITaskSubscriptionEvents extends IEvent {\n\t(event: \"gotTask\" | \"lostTask\", listener: () => void);\n}\n\n/**\n * TaskSubscription works with an AgentScheduler to make it easier to monitor a specific task ownership.\n * @alpha\n */\nexport class TaskSubscription extends TypedEventEmitter<ITaskSubscriptionEvents> {\n\tprivate subscribed: boolean = false;\n\n\t/**\n\t * @param agentScheduler - The AgentScheduler that will be subscribed against\n\t * @param taskId - The string ID of the task to subscribe against\n\t */\n\tconstructor(\n\t\tprivate readonly agentScheduler: IAgentScheduler,\n\t\tpublic readonly taskId: string,\n\t) {\n\t\tsuper();\n\t\tagentScheduler.on(\"picked\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"gotTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"released\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"lost\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if currently holding ownership of the task.\n\t * @returns true if currently the task owner, false otherwise.\n\t */\n\tpublic haveTask() {\n\t\treturn this.agentScheduler.pickedTasks().includes(this.taskId);\n\t}\n\n\t/**\n\t * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.\n\t * This is safe to call multiple times across multiple TaskSubscriptions.\n\t */\n\tpublic volunteer() {\n\t\tif (!this.subscribed) {\n\t\t\t// AgentScheduler throws if the same task is picked twice but we don't care because our\n\t\t\t// worker does nothing. We only care that the AgentScheduler is trying to pick.\n\t\t\t// We also don't care if we throw due to failing the interactive check, because then we'll\n\t\t\t// just appear to never get the task.\n\t\t\tthis.agentScheduler.pick(this.taskId, async () => {}).catch(() => {});\n\t\t\tthis.subscribed = true;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"taskSubscription.js","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAiE;AAWjE;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,gCAA0C;IAG/E;;;OAGG;IACH,YACkB,cAA+B,EAChC,MAAc;QAE9B,KAAK,EAAE,CAAC;QAHS,mBAAc,GAAd,cAAc,CAAiB;QAChC,WAAM,GAAN,MAAM,CAAQ;QARvB,eAAU,GAAY,KAAK,CAAC;QAWnC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAe,EAAE,EAAE;YAC/C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACrB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,OAAe,EAAE,EAAE;YACjD,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YAC7C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,uFAAuF;YACvF,gFAAgF;YAChF,0FAA0F;YAC1F,qCAAqC;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACvB;IACF,CAAC;CACD;AAnDD,4CAmDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IAgentScheduler } from \"./agent.js\";\n\n/**\n * Events emitted by {@link TaskSubscription}.\n * @alpha\n */\nexport interface ITaskSubscriptionEvents extends IEvent {\n\t(event: \"gotTask\" | \"lostTask\", listener: () => void);\n}\n\n/**\n * TaskSubscription works with an AgentScheduler to make it easier to monitor a specific task ownership.\n * @alpha\n */\nexport class TaskSubscription extends TypedEventEmitter<ITaskSubscriptionEvents> {\n\tprivate subscribed: boolean = false;\n\n\t/**\n\t * @param agentScheduler - The AgentScheduler that will be subscribed against\n\t * @param taskId - The string ID of the task to subscribe against\n\t */\n\tconstructor(\n\t\tprivate readonly agentScheduler: IAgentScheduler,\n\t\tpublic readonly taskId: string,\n\t) {\n\t\tsuper();\n\t\tagentScheduler.on(\"picked\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"gotTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"released\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"lost\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if currently holding ownership of the task.\n\t * @returns true if currently the task owner, false otherwise.\n\t */\n\tpublic haveTask() {\n\t\treturn this.agentScheduler.pickedTasks().includes(this.taskId);\n\t}\n\n\t/**\n\t * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.\n\t * This is safe to call multiple times across multiple TaskSubscriptions.\n\t */\n\tpublic volunteer() {\n\t\tif (!this.subscribed) {\n\t\t\t// AgentScheduler throws if the same task is picked twice but we don't care because our\n\t\t\t// worker does nothing. We only care that the AgentScheduler is trying to pick.\n\t\t\t// We also don't care if we throw due to failing the interactive check, because then we'll\n\t\t\t// just appear to never get the task.\n\t\t\tthis.agentScheduler.pick(this.taskId, async () => {}).catch(() => {});\n\t\t\tthis.subscribed = true;\n\t\t}\n\t}\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.3"
8
+ "packageVersion": "7.42.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -71,4 +71,4 @@ export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<
71
71
  */
72
72
  pickedTasks(): string[];
73
73
  }
74
- //# sourceMappingURL=agent.d.mts.map
74
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,sBAA0C,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACpD;;;;;;;;;;;;;;;;OAgBG;IACH,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,OAAE;CAC5E;AAED;;;GAGG;AACH,MAAM,WAAW,eAChB,SAAQ,sBAAsB,EAC7B,cAAc,CAAC,qBAAqB,CAAC,EACrC,cAAc;IACf;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,OAAO,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,WAAW,IAAI,MAAM,EAAE,CAAC;CACxB"}
@@ -6,4 +6,4 @@
6
6
  * @alpha
7
7
  */
8
8
  export const IAgentScheduler = "IAgentScheduler";
9
- //# sourceMappingURL=agent.mjs.map
9
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAiC,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, IFluidLoadable } from \"@fluidframework/core-interfaces\";\n\n/**\n * @alpha\n */\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\n/**\n * @alpha\n */\nexport interface IProvideAgentScheduler {\n\treadonly IAgentScheduler: IAgentScheduler;\n}\n\n/**\n * Events emitted by {@link (IAgentScheduler:interface)}.\n * @alpha\n */\nexport interface IAgentSchedulerEvents extends IEvent {\n\t/**\n\t * Event when ownership of task changes\n\t * @param event - name of the event:\n\t *\n\t * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n\t * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n\t * automatically, unless release() is called\n\t *\n\t * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n\t * re-acquire the task, unless pick() is called.\n\t *\n\t * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n\t * Task will be picked up again by some connected client (this client will try as well,\n\t * unless release() is called)\n\t *\n\t * @param listener - callback notified when change happened for particular key\n\t */\n\t(event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n * @alpha\n */\nexport interface IAgentScheduler\n\textends IProvideAgentScheduler,\n\t\tIEventProvider<IAgentSchedulerEvents>,\n\t\tIFluidLoadable {\n\t/**\n\t * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n\t * a new agent to run but does not have the capability to run the agent inside the host.\n\t * Client can call pick() later if the capability changes.\n\t *\n\t * This method should only be called once per task. Duplicate calls will be rejected.\n\t */\n\tregister(...taskUrls: string[]): Promise<void>;\n\n\t/**\n\t * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n\t * Resolves when the tasks are assigned to one of the connected clients.\n\t *\n\t * This method should only be called once per task. Duplicate calls will be rejected.\n\t *\n\t * @param worker - callback to run when task is picked up.\n\t */\n\tpick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n\t/**\n\t * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n\t *\n\t * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n\t * App can call pickedTasks() to get the picked list first.\n\t */\n\trelease(...taskUrls: string[]): Promise<void>;\n\n\t/**\n\t * Returns a list of all tasks running on this client\n\t */\n\tpickedTasks(): string[];\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent.mjs";
6
- export { AgentSchedulerFactory } from "./scheduler.mjs";
7
- export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription.mjs";
8
- //# sourceMappingURL=index.d.mts.map
5
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent.js";
6
+ export { AgentSchedulerFactory } from "./scheduler.js";
7
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { IAgentScheduler } from "./agent.js";
6
+ export { AgentSchedulerFactory } from "./scheduler.js";
7
+ export { TaskSubscription } from "./taskSubscription.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAiD,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAA2B,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from \"./agent.js\";\nexport { AgentSchedulerFactory } from \"./scheduler.js\";\nexport { ITaskSubscriptionEvents, TaskSubscription } from \"./taskSubscription.js\";\n"]}
@@ -8,7 +8,7 @@ import { FluidDataStoreRuntime } from "@fluidframework/datastore";
8
8
  import { ConsensusRegisterCollection } from "@fluidframework/register-collection";
9
9
  import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
10
10
  import { IFluidDataStoreContext, IFluidDataStoreFactory, NamedFluidDataStoreRegistryEntry } from "@fluidframework/runtime-definitions";
11
- import { IAgentScheduler, IAgentSchedulerEvents } from "./agent.mjs";
11
+ import { IAgentScheduler, IAgentSchedulerEvents } from "./agent.js";
12
12
  export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {
13
13
  private readonly runtime;
14
14
  private readonly context;
@@ -16,6 +16,7 @@ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEve
16
16
  static load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean): Promise<AgentScheduler>;
17
17
  get IAgentScheduler(): this;
18
18
  get IFluidLoadable(): this;
19
+ private readonly logger;
19
20
  private get clientId();
20
21
  private readonly registeredTasks;
21
22
  private readonly locallyRunnableTasks;
@@ -51,4 +52,4 @@ export declare class AgentSchedulerFactory implements IFluidDataStoreFactory {
51
52
  static createChildInstance(parentContext: IFluidDataStoreContext): Promise<IAgentScheduler>;
52
53
  instantiateDataStore(context: IFluidDataStoreContext, existing: boolean): Promise<FluidDataStoreRuntime>;
53
54
  }
54
- //# sourceMappingURL=scheduler.d.mts.map
55
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAe,YAAY,EAAY,MAAM,iCAAiC,CAAC;AACtF,OAAO,E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AC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnD,WAAW,IAAI,MAAM,EAAE;YAIhB,YAAY;YAkBZ,WAAW;YAYX,UAAU;IASxB,OAAO,CAAC,eAAe;YAIT,SAAS;IAIvB,OAAO,CAAC,UAAU;IAiFlB,OAAO,CAAC,iBAAiB;YAcX,gBAAgB;IAuB9B,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,cAAc;CAGtB;AA6BD;;GAEG;AACH,qBAAa,qBAAsB,YAAW,sBAAsB;IACnE,gBAAuB,IAAI,gBAAgB;IAC3C,SAAgB,IAAI,gBAA8B;IAElD,IAAW,sBAAsB,SAEhC;IAED,WAAkB,aAAa,IAAI,gCAAgC,CAElE;WAEmB,mBAAmB,CACtC,aAAa,EAAE,sBAAsB,GACnC,OAAO,CAAC,eAAe,CAAC;IAcd,oBAAoB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,OAAO,GACf,OAAO,CAAC,qBAAqB,CAAC;CASjC"}
@@ -9,7 +9,7 @@ import { AttachState } from "@fluidframework/container-definitions";
9
9
  import { SharedMap } from "@fluidframework/map";
10
10
  import { ConsensusRegisterCollection } from "@fluidframework/register-collection";
11
11
  import { v4 as uuid } from "uuid";
12
- import { tagCodeArtifacts, UsageError } from "@fluidframework/telemetry-utils";
12
+ import { createChildLogger, tagCodeArtifacts, UsageError, } from "@fluidframework/telemetry-utils";
13
13
  // Note: making sure this ID is unique and does not collide with storage provided clientID
14
14
  const UnattachedClientId = `${uuid()}_unattached`;
15
15
  const mapWait = async (map, key) => {
@@ -84,6 +84,7 @@ export class AgentScheduler extends TypedEventEmitter {
84
84
  // Set of registered tasks client is currently running.
85
85
  // It's subset of this.locallyRunnableTasks
86
86
  this.runningTasks = new Set();
87
+ this.logger = createChildLogger({ logger: runtime.logger });
87
88
  // We are expecting this class to have many listeners, so we suppress noisy "MaxListenersExceededWarning" logging.
88
89
  super.setMaxListeners(0);
89
90
  this._handle = new FluidObjectHandle(this, "", this.runtime.objectsRoutingContext);
@@ -347,7 +348,7 @@ export class AgentScheduler extends TypedEventEmitter {
347
348
  }
348
349
  }
349
350
  sendErrorEvent(eventName, error, key) {
350
- this.runtime.logger.sendErrorEvent({ eventName, key }, error);
351
+ this.logger.sendErrorEvent({ eventName, key }, error);
351
352
  }
352
353
  }
353
354
  class AgentSchedulerRuntime extends FluidDataStoreRuntime {
@@ -398,4 +399,4 @@ export class AgentSchedulerFactory {
398
399
  }
399
400
  }
400
401
  AgentSchedulerFactory.type = "_scheduler";
401
- //# sourceMappingURL=scheduler.mjs.map
402
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EACN,qBAAqB,EACrB,iBAAiB,GAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAA6B,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAOlF,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,GAEV,MAAM,iCAAiC,CAAC;AAGzC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAI,EAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,EAAW,GAAe,EAAE,GAAW,EAAc,EAAE;IAC3E,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAI,GA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n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { FluidObject, IFluidHandle, IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tISharedObjectRegistry,\n} from \"@fluidframework/datastore\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ISharedMap, IValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { ConsensusRegisterCollection } from \"@fluidframework/register-collection\";\nimport { IFluidDataStoreRuntime, IChannelFactory } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\tcreateChildLogger,\n\ttagCodeArtifacts,\n\tUsageError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils\";\nimport { IAgentScheduler, IAgentSchedulerEvents } from \"./agent.js\";\n\n// Note: making sure this ID is unique and does not collide with storage provided clientID\nconst UnattachedClientId = `${uuid()}_unattached`;\n\nconst mapWait = async <T = any>(map: ISharedMap, key: string): Promise<T> => {\n\tconst maybeValue = map.get<T>(key);\n\tif (maybeValue !== undefined) {\n\t\treturn maybeValue;\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst handler = (changed: IValueChanged) => {\n\t\t\tif (changed.key === key) {\n\t\t\t\tmap.off(\"valueChanged\", handler);\n\t\t\t\tconst value = map.get<T>(changed.key);\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tthrow new Error(\"Unexpected valueChanged result\");\n\t\t\t\t}\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t};\n\t\tmap.on(\"valueChanged\", handler);\n\t});\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n\textends TypedEventEmitter<IAgentSchedulerEvents>\n\timplements IAgentScheduler\n{\n\tpublic static async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t) {\n\t\tlet root: ISharedMap;\n\t\tlet consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n\t\tif (!existing) {\n\t\t\troot = SharedMap.create(runtime, \"root\");\n\t\t\troot.bindToContext();\n\t\t\tconsensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n\t\t\tconsensusRegisterCollection.bindToContext();\n\t\t\troot.set(schedulerId, consensusRegisterCollection.handle);\n\t\t} else {\n\t\t\troot = (await runtime.getChannel(\"root\")) as ISharedMap;\n\t\t\tconst handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(\n\t\t\t\troot,\n\t\t\t\tschedulerId,\n\t\t\t);\n\t\t\tassert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n\t\t\tconsensusRegisterCollection = await handle.get();\n\t\t}\n\t\tconst agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n\t\tagentScheduler.initialize();\n\n\t\treturn agentScheduler;\n\t}\n\n\tpublic get IAgentScheduler() {\n\t\treturn this;\n\t}\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate get clientId(): string {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn UnattachedClientId;\n\t\t}\n\t\tconst clientId = this.runtime.clientId;\n\t\tassert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n\t\treturn clientId;\n\t}\n\n\t// Set of tasks registered by this client.\n\t// Has no relationship with lists below.\n\t// The only requirement here - a task can be registered by a client only once.\n\t// Other clients can pick these tasks.\n\tprivate readonly registeredTasks = new Set<string>();\n\n\t// List of all tasks client is capable of running (essentially expressed desire to run)\n\t// Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n\t// This is a strict superset of tasks running in the client.\n\tprivate readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n\t// Set of registered tasks client is currently running.\n\t// It's subset of this.locallyRunnableTasks\n\tprivate runningTasks = new Set<string>();\n\n\tprivate readonly _handle: IFluidHandle<this>;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\t\tprivate readonly context: IFluidDataStoreContext,\n\t\tprivate readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger: runtime.logger });\n\t\t// We are expecting this class to have many listeners, so we suppress noisy \"MaxListenersExceededWarning\" logging.\n\t\tsuper.setMaxListeners(0);\n\t\tthis._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n\t}\n\n\tpublic get handle() {\n\t\treturn this._handle;\n\t}\n\n\tpublic async register(...taskUrls: string[]): Promise<void> {\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (this.registeredTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task is already registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\tconst unregisteredTasks: string[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tthis.registeredTasks.add(taskUrl);\n\t\t\t// Only register for a new task.\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined) {\n\t\t\t\tunregisteredTasks.push(taskUrl);\n\t\t\t}\n\t\t}\n\t\treturn this.registerCore(unregisteredTasks);\n\t}\n\n\tpublic async pick(taskUrl: string, worker: () => Promise<void>): Promise<void> {\n\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\tthrow new UsageError(`Task is already attempted`, tagCodeArtifacts({ taskUrl }));\n\t\t}\n\t\tthis.locallyRunnableTasks.set(taskUrl, worker);\n\n\t\t// We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n\t\t// either perform this check proactively and call conditionally, or catch the error (in which case\n\t\t// they can know they will not get the task).\n\t\tassert(\n\t\t\tthis.context.deltaManager.clientDetails.capabilities.interactive,\n\t\t\t0x118 /* \"Bad client interactive check\" */,\n\t\t);\n\n\t\t// Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n\t\tif (this.isActive()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined || currentClient === null) {\n\t\t\t\tawait this.writeCore(taskUrl, this.clientId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async release(...taskUrls: string[]): Promise<void> {\n\t\tconst active = this.isActive();\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (!this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task was never registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\tif (!this.runningTasks.has(taskUrl)) {\n\t\t\t\t// If we got disconnected (and are attached), tasks that we WERE picked for at the time of disconnect\n\t\t\t\t// will still show us as holding the task according to getTaskClientId (the CRC is stale), but we\n\t\t\t\t// should not try to release because our disconnect will already result in either someone else or\n\t\t\t\t// ourselves clearing the task upon reconnect.\n\t\t\t\t// This UsageError is to enforce that the caller should check AgentScheduler.pickedTasks before trying\n\t\t\t\t// to release a task.\n\t\t\t\tthrow new UsageError(`Task is not currently picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\t// We may only release tasks that we KNOW we hold (detached state or connected and own the CRC). If we're\n\t\t\t// attached+disconnected then we'll lose the task automatically, and so may not release manually (someone\n\t\t\t// else might hold it by the time we reconnect)\n\t\t\tassert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n\t\t\tif (this.getTaskClientId(taskUrl) !== this.clientId) {\n\t\t\t\tthrow new UsageError(`Task was never picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\treturn this.releaseCore([...taskUrls]);\n\t}\n\n\tpublic pickedTasks(): string[] {\n\t\treturn Array.from(this.runningTasks.values());\n\t}\n\n\tprivate async registerCore(taskUrls: string[]): Promise<void> {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst registersP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tregistersP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(registersP);\n\n\t\t\t// The registers should have up to date results now. Check the status.\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tconst taskStatus = this.getTaskClientId(taskUrl);\n\n\t\t\t\t// Task should be either registered (null) or picked up.\n\t\t\t\tassert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async releaseCore(taskUrls: string[]) {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst releasesP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\t// Remove from local map so that it can be picked later.\n\t\t\t\tthis.locallyRunnableTasks.delete(taskUrl);\n\t\t\t\treleasesP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(releasesP);\n\t\t}\n\t}\n\n\tprivate async clearTasks(taskUrls: string[]) {\n\t\tassert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n\t\tconst clearP: Promise<void>[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tclearP.push(this.writeCore(taskUrl, null));\n\t\t}\n\t\tawait Promise.all(clearP);\n\t}\n\n\tprivate getTaskClientId(url: string): string | null | undefined {\n\t\treturn this.consensusRegisterCollection.read(url);\n\t}\n\n\tprivate async writeCore(key: string, clientId: string | null): Promise<void> {\n\t\tawait this.consensusRegisterCollection.write(key, clientId);\n\t}\n\n\tprivate initialize() {\n\t\tconst quorum = this.runtime.getQuorum();\n\t\t// A client left the quorum. Iterate and clear tasks held by that client.\n\t\t// Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n\t\t// Probably okay for now to have every client try to do this.\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tquorum.on(\"removeMember\", async (clientId: string) => {\n\t\t\tassert(\n\t\t\t\tthis.runtime.objectsRoutingContext.isAttached,\n\t\t\t\t0x11c /* \"Detached object routing context\" */,\n\t\t\t);\n\t\t\t// Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n\t\t\tif (this.isActive()) {\n\t\t\t\tconst tasks: Promise<any>[] = [];\n\t\t\t\tconst leftTasks: string[] = [];\n\t\t\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\t\t\tif (this.getTaskClientId(taskUrl) === clientId) {\n\t\t\t\t\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tleftTasks.push(taskUrl);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttasks.push(this.clearTasks(leftTasks));\n\t\t\t\tawait Promise.all(tasks).catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// Listeners for new/released tasks. All clients will try to grab at the same time.\n\t\t// May be we want a randomized timer (Something like raft) to reduce chattiness?\n\t\tthis.consensusRegisterCollection.on(\n\t\t\t\"atomicChanged\",\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\tasync (key: string, currentClient: string | null) => {\n\t\t\t\t// Check if this client was chosen.\n\t\t\t\tif (this.isActive() && currentClient === this.clientId) {\n\t\t\t\t\tthis.onNewTaskAssigned(key);\n\t\t\t\t} else {\n\t\t\t\t\t// The call below mutates the consensusRegisterCollection in\n\t\t\t\t\t// its event handler, which is not safe.\n\t\t\t\t\t// We need to force this to be part of a different batch of ops by\n\t\t\t\t\t// scheduling a microtask in order to work around the current validations.\n\t\t\t\t\t// This is not recommended and should be avoided.\n\t\t\t\t\tawait Promise.resolve().then(async () => {\n\t\t\t\t\t\tawait this.onTaskReassigned(key, currentClient);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tif (this.isActive()) {\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tthis.runtime.on(\"connected\", () => {\n\t\t\tif (this.isActive()) {\n\t\t\t\tthis.initializeCore();\n\t\t\t}\n\t\t});\n\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tthis.runtime\n\t\t\t\t.waitAttached()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.clearRunningTasks();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n\t\t\t\t});\n\t\t}\n\n\t\tthis.runtime.on(\"disconnected\", () => {\n\t\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t\tthis.clearRunningTasks();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate onNewTaskAssigned(key: string) {\n\t\tassert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n\t\tthis.runningTasks.add(key);\n\t\tconst worker = this.locallyRunnableTasks.get(key);\n\t\tif (worker === undefined) {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n\t\t} else {\n\t\t\tthis.emit(\"picked\", key);\n\t\t\tworker().catch((error) => {\n\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async onTaskReassigned(key: string, currentClient: string | null) {\n\t\tif (this.runningTasks.has(key)) {\n\t\t\tthis.runningTasks.delete(key);\n\t\t\tthis.emit(\"released\", key);\n\t\t}\n\t\tassert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n\t\tif (this.isActive()) {\n\t\t\t// attempt to pick up task if we are connected.\n\t\t\t// If not, initializeCore() will do it when connected\n\t\t\tif (currentClient === null) {\n\t\t\t\tif (this.locallyRunnableTasks.has(key)) {\n\t\t\t\t\tawait this.writeCore(key, this.clientId);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the op came from dropped client\n\t\t\t// This could happen when \"old\" ops are submitted on reconnection.\n\t\t\t// They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n\t\t\telse if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tawait this.writeCore(key, null);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isActive() {\n\t\t// Scheduler should be active in detached container.\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!this.runtime.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n\t\t// here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n\t\treturn this.context.deltaManager.active;\n\t}\n\n\tprivate initializeCore() {\n\t\t// Nobody released the tasks held by last client in previous session.\n\t\t// Check to see if this client needs to do this.\n\t\tconst clearCandidates: string[] = [];\n\t\tconst tasks: Promise<any>[] = [];\n\n\t\tfor (const [taskUrl] of this.locallyRunnableTasks) {\n\t\t\tif (!this.getTaskClientId(taskUrl)) {\n\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tclearCandidates.push(taskUrl);\n\t\t\t}\n\t\t}\n\n\t\ttasks.push(this.clearTasks(clearCandidates));\n\n\t\tPromise.all(tasks).catch((error) => {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_InitError\", error);\n\t\t});\n\t}\n\n\tprivate clearRunningTasks() {\n\t\tconst tasks = this.runningTasks;\n\t\tthis.runningTasks = new Set<string>();\n\n\t\tif (this.isActive()) {\n\t\t\t// Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n\t\t\t// If we are simply disconnected, then proper cleanup will be done on connection.\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tfor (const task of tasks) {\n\t\t\tthis.emit(\"lost\", task);\n\t\t}\n\t}\n\n\tprivate sendErrorEvent(eventName: string, error: any, key?: string) {\n\t\tthis.logger.sendErrorEvent({ eventName, key }, error);\n\t}\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n\tconstructor(\n\t\tdataStoreContext: IFluidDataStoreContext,\n\t\tsharedObjectRegistry: ISharedObjectRegistry,\n\t\texisting: boolean,\n\t) {\n\t\tsuper(dataStoreContext, sharedObjectRegistry, existing, async () =>\n\t\t\tAgentScheduler.load(this, dataStoreContext, existing),\n\t\t);\n\t}\n\tpublic async request(request: IRequest) {\n\t\tconst response = await super.request(request);\n\t\tif (response.status === 404) {\n\t\t\tif (request.url === \"\" || request.url === \"/\") {\n\t\t\t\tconst agentScheduler = await this.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tagentScheduler !== undefined,\n\t\t\t\t\t0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */,\n\t\t\t\t);\n\n\t\t\t\treturn { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n\t\t\t}\n\t\t}\n\t\treturn response;\n\t}\n}\n\n/**\n * @alpha\n */\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n\tpublic static readonly type = \"_scheduler\";\n\tpublic readonly type = AgentSchedulerFactory.type;\n\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\tpublic static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(new AgentSchedulerFactory())];\n\t}\n\n\tpublic static async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t): Promise<IAgentScheduler> {\n\t\tconst packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n\t\tconst dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n\t\tconst entryPoint: FluidObject<IAgentScheduler> = await dataStore.entryPoint.get();\n\n\t\t// AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n\t\t// while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n\t\tassert(\n\t\t\tentryPoint.IAgentScheduler !== undefined,\n\t\t\t0x467 /* The data store's entryPoint is not an AgentScheduler! */,\n\t\t);\n\t\treturn entryPoint as unknown as AgentScheduler;\n\t}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst mapFactory = SharedMap.getFactory();\n\t\tconst consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\t\tdataTypes.set(mapFactory.type, mapFactory);\n\t\tdataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n\t\treturn new AgentSchedulerRuntime(context, dataTypes, existing);\n\t}\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { IEvent } from "@fluidframework/core-interfaces";
6
6
  import { TypedEventEmitter } from "@fluid-internal/client-utils";
7
- import { IAgentScheduler } from "./agent.mjs";
7
+ import { IAgentScheduler } from "./agent.js";
8
8
  /**
9
9
  * Events emitted by {@link TaskSubscription}.
10
10
  * @alpha
@@ -36,4 +36,4 @@ export declare class TaskSubscription extends TypedEventEmitter<ITaskSubscriptio
36
36
  */
37
37
  volunteer(): void;
38
38
  }
39
- //# sourceMappingURL=taskSubscription.d.mts.map
39
+ //# sourceMappingURL=taskSubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskSubscription.d.ts","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,MAAM;IACtD,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CACtD;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,uBAAuB,CAAC;IAQ9E,OAAO,CAAC,QAAQ,CAAC,cAAc;aACf,MAAM,EAAE,MAAM;IAR/B,OAAO,CAAC,UAAU,CAAkB;IAEpC;;;OAGG;gBAEe,cAAc,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM;IAoB/B;;;OAGG;IACI,QAAQ;IAIf;;;OAGG;IACI,SAAS;CAUhB"}
@@ -55,4 +55,4 @@ export class TaskSubscription extends TypedEventEmitter {
55
55
  }
56
56
  }
57
57
  }
58
- //# sourceMappingURL=taskSubscription.mjs.map
58
+ //# sourceMappingURL=taskSubscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taskSubscription.js","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAWjE;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,iBAA0C;IAG/E;;;OAGG;IACH,YACkB,cAA+B,EAChC,MAAc;QAE9B,KAAK,EAAE,CAAC;QAHS,mBAAc,GAAd,cAAc,CAAiB;QAChC,WAAM,GAAN,MAAM,CAAQ;QARvB,eAAU,GAAY,KAAK,CAAC;QAWnC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAe,EAAE,EAAE;YAC/C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACrB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,OAAe,EAAE,EAAE;YACjD,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YAC7C,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE;gBAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACtB;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,uFAAuF;YACvF,gFAAgF;YAChF,0FAA0F;YAC1F,qCAAqC;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACvB;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IAgentScheduler } from \"./agent.js\";\n\n/**\n * Events emitted by {@link TaskSubscription}.\n * @alpha\n */\nexport interface ITaskSubscriptionEvents extends IEvent {\n\t(event: \"gotTask\" | \"lostTask\", listener: () => void);\n}\n\n/**\n * TaskSubscription works with an AgentScheduler to make it easier to monitor a specific task ownership.\n * @alpha\n */\nexport class TaskSubscription extends TypedEventEmitter<ITaskSubscriptionEvents> {\n\tprivate subscribed: boolean = false;\n\n\t/**\n\t * @param agentScheduler - The AgentScheduler that will be subscribed against\n\t * @param taskId - The string ID of the task to subscribe against\n\t */\n\tconstructor(\n\t\tprivate readonly agentScheduler: IAgentScheduler,\n\t\tpublic readonly taskId: string,\n\t) {\n\t\tsuper();\n\t\tagentScheduler.on(\"picked\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"gotTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"released\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"lost\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if currently holding ownership of the task.\n\t * @returns true if currently the task owner, false otherwise.\n\t */\n\tpublic haveTask() {\n\t\treturn this.agentScheduler.pickedTasks().includes(this.taskId);\n\t}\n\n\t/**\n\t * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.\n\t * This is safe to call multiple times across multiple TaskSubscriptions.\n\t */\n\tpublic volunteer() {\n\t\tif (!this.subscribed) {\n\t\t\t// AgentScheduler throws if the same task is picked twice but we don't care because our\n\t\t\t// worker does nothing. We only care that the AgentScheduler is trying to pick.\n\t\t\t// We also don't care if we throw due to failing the interactive check, because then we'll\n\t\t\t// just appear to never get the task.\n\t\t\tthis.agentScheduler.pick(this.taskId, async () => {}).catch(() => {});\n\t\t\tthis.subscribed = true;\n\t\t}\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/agent-scheduler",
3
- "version": "2.0.0-rc.1.0.4",
3
+ "version": "2.0.0-rc.2.0.0",
4
4
  "description": "Built in runtime object for distributing agents across instances of a container",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -11,89 +11,79 @@
11
11
  "license": "MIT",
12
12
  "author": "Microsoft and contributors",
13
13
  "sideEffects": false,
14
+ "type": "module",
14
15
  "exports": {
15
16
  ".": {
16
17
  "import": {
17
- "types": "./lib/index.d.mts",
18
- "default": "./lib/index.mjs"
18
+ "types": "./lib/index.d.ts",
19
+ "default": "./lib/index.js"
19
20
  },
20
21
  "require": {
21
22
  "types": "./dist/index.d.ts",
22
23
  "default": "./dist/index.js"
23
24
  }
24
25
  },
25
- "./alpha": {
26
+ "./public": {
26
27
  "import": {
27
- "types": "./lib/agent-scheduler-alpha.d.mts",
28
- "default": "./lib/index.mjs"
28
+ "types": "./lib/agent-scheduler-public.d.ts",
29
+ "default": "./lib/index.js"
29
30
  },
30
31
  "require": {
31
- "types": "./dist/agent-scheduler-alpha.d.ts",
32
+ "types": "./dist/agent-scheduler-public.d.ts",
32
33
  "default": "./dist/index.js"
33
34
  }
34
35
  },
35
- "./beta": {
36
+ "./alpha": {
36
37
  "import": {
37
- "types": "./lib/agent-scheduler-beta.d.mts",
38
- "default": "./lib/index.mjs"
38
+ "types": "./lib/agent-scheduler-alpha.d.ts",
39
+ "default": "./lib/index.js"
39
40
  },
40
41
  "require": {
41
- "types": "./dist/agent-scheduler-beta.d.ts",
42
+ "types": "./dist/agent-scheduler-alpha.d.ts",
42
43
  "default": "./dist/index.js"
43
44
  }
44
45
  },
45
46
  "./internal": {
46
47
  "import": {
47
- "types": "./lib/index.d.mts",
48
- "default": "./lib/index.mjs"
48
+ "types": "./lib/index.d.ts",
49
+ "default": "./lib/index.js"
49
50
  },
50
51
  "require": {
51
52
  "types": "./dist/index.d.ts",
52
53
  "default": "./dist/index.js"
53
54
  }
54
- },
55
- "./public": {
56
- "import": {
57
- "types": "./lib/agent-scheduler-public.d.mts",
58
- "default": "./lib/index.mjs"
59
- },
60
- "require": {
61
- "types": "./dist/agent-scheduler-public.d.ts",
62
- "default": "./dist/index.js"
63
- }
64
55
  }
65
56
  },
66
57
  "main": "dist/index.js",
67
- "module": "lib/index.mjs",
68
58
  "types": "dist/index.d.ts",
69
59
  "dependencies": {
70
- "@fluid-internal/client-utils": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
71
- "@fluidframework/container-definitions": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
72
- "@fluidframework/core-interfaces": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
73
- "@fluidframework/core-utils": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
74
- "@fluidframework/datastore": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
75
- "@fluidframework/datastore-definitions": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
76
- "@fluidframework/map": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
77
- "@fluidframework/register-collection": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
78
- "@fluidframework/runtime-definitions": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
79
- "@fluidframework/runtime-utils": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
80
- "@fluidframework/telemetry-utils": ">=2.0.0-rc.1.0.4 <2.0.0-rc.1.1.0",
60
+ "@fluid-internal/client-utils": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
61
+ "@fluidframework/container-definitions": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
62
+ "@fluidframework/core-interfaces": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
63
+ "@fluidframework/core-utils": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
64
+ "@fluidframework/datastore": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
65
+ "@fluidframework/datastore-definitions": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
66
+ "@fluidframework/map": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
67
+ "@fluidframework/register-collection": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
68
+ "@fluidframework/runtime-definitions": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
69
+ "@fluidframework/runtime-utils": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
70
+ "@fluidframework/telemetry-utils": ">=2.0.0-rc.2.0.0 <2.0.0-rc.2.1.0",
81
71
  "uuid": "^9.0.0"
82
72
  },
83
73
  "devDependencies": {
84
74
  "@arethetypeswrong/cli": "^0.13.3",
85
- "@fluid-tools/build-cli": "^0.29.0",
75
+ "@fluid-tools/build-cli": "^0.34.0",
86
76
  "@fluidframework/agent-scheduler-previous": "npm:@fluidframework/agent-scheduler@2.0.0-internal.8.0.0",
87
77
  "@fluidframework/build-common": "^2.0.3",
88
- "@fluidframework/build-tools": "^0.29.0",
89
- "@fluidframework/eslint-config-fluid": "^3.2.0",
90
- "@microsoft/api-extractor": "^7.38.3",
78
+ "@fluidframework/build-tools": "^0.34.0",
79
+ "@fluidframework/eslint-config-fluid": "^4.0.0",
80
+ "@microsoft/api-extractor": "^7.42.3",
91
81
  "@types/node": "^18.19.0",
82
+ "@types/uuid": "^9.0.2",
92
83
  "copyfiles": "^2.4.1",
93
- "eslint": "~8.50.0",
84
+ "eslint": "~8.55.0",
94
85
  "prettier": "~3.0.3",
95
86
  "rimraf": "^4.4.0",
96
- "tsc-multi": "^1.1.0",
97
87
  "typescript": "~5.1.6"
98
88
  },
99
89
  "fluidBuild": {
@@ -113,13 +103,15 @@
113
103
  },
114
104
  "scripts": {
115
105
  "api": "fluid-build . --task api",
116
- "api-extractor:commonjs": "api-extractor run --local",
117
- "api-extractor:esnext": "api-extractor run --config ./api-extractor-esm.json",
106
+ "api-extractor:commonjs": "api-extractor run --config ./api-extractor-cjs.json",
107
+ "api-extractor:esnext": "api-extractor run --local",
118
108
  "build": "fluid-build . --task build",
119
109
  "build:compile": "fluid-build . --task compile",
120
110
  "build:docs": "fluid-build . --task api",
121
- "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
122
- "build:test": "tsc --project ./src/test/tsconfig.json",
111
+ "build:esnext": "tsc --project ./tsconfig.json",
112
+ "build:test": "npm run build:test:cjs && npm run build:test:esm",
113
+ "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
114
+ "build:test:esm": "tsc --project ./src/test/tsconfig.json",
123
115
  "check:are-the-types-wrong": "attw --pack . --entrypoints .",
124
116
  "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
125
117
  "ci:build:docs": "api-extractor run",
@@ -132,7 +124,7 @@
132
124
  "lint:fix": "npm run prettier:fix && npm run eslint:fix",
133
125
  "prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
134
126
  "prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
135
- "tsc": "tsc",
127
+ "tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
136
128
  "typetests:gen": "fluid-type-test-generator",
137
129
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
138
130
  }
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent";
7
- export { AgentSchedulerFactory } from "./scheduler";
8
- export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription";
6
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent.js";
7
+ export { AgentSchedulerFactory } from "./scheduler.js";
8
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription.js";
package/src/scheduler.ts CHANGED
@@ -21,8 +21,13 @@ import {
21
21
  NamedFluidDataStoreRegistryEntry,
22
22
  } from "@fluidframework/runtime-definitions";
23
23
  import { v4 as uuid } from "uuid";
24
- import { tagCodeArtifacts, UsageError } from "@fluidframework/telemetry-utils";
25
- import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
24
+ import {
25
+ createChildLogger,
26
+ tagCodeArtifacts,
27
+ UsageError,
28
+ type ITelemetryLoggerExt,
29
+ } from "@fluidframework/telemetry-utils";
30
+ import { IAgentScheduler, IAgentSchedulerEvents } from "./agent.js";
26
31
 
27
32
  // Note: making sure this ID is unique and does not collide with storage provided clientID
28
33
  const UnattachedClientId = `${uuid()}_unattached`;
@@ -89,6 +94,8 @@ export class AgentScheduler
89
94
  return this;
90
95
  }
91
96
 
97
+ private readonly logger: ITelemetryLoggerExt;
98
+
92
99
  private get clientId(): string {
93
100
  if (this.runtime.attachState === AttachState.Detached) {
94
101
  return UnattachedClientId;
@@ -121,6 +128,7 @@ export class AgentScheduler
121
128
  private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,
122
129
  ) {
123
130
  super();
131
+ this.logger = createChildLogger({ logger: runtime.logger });
124
132
  // We are expecting this class to have many listeners, so we suppress noisy "MaxListenersExceededWarning" logging.
125
133
  super.setMaxListeners(0);
126
134
  this._handle = new FluidObjectHandle(this, "", this.runtime.objectsRoutingContext);
@@ -423,7 +431,7 @@ export class AgentScheduler
423
431
  }
424
432
 
425
433
  private sendErrorEvent(eventName: string, error: any, key?: string) {
426
- this.runtime.logger.sendErrorEvent({ eventName, key }, error);
434
+ this.logger.sendErrorEvent({ eventName, key }, error);
427
435
  }
428
436
  }
429
437
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { IEvent } from "@fluidframework/core-interfaces";
7
7
  import { TypedEventEmitter } from "@fluid-internal/client-utils";
8
- import { IAgentScheduler } from "./agent";
8
+ import { IAgentScheduler } from "./agent.js";
9
9
 
10
10
  /**
11
11
  * Events emitted by {@link TaskSubscription}.
@@ -0,0 +1,7 @@
1
+ {
2
+ // This config must be used in a "type": "commonjs" environment. (Use fluid-tsc commonjs.)
3
+ "extends": "./tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ },
7
+ }
package/tsconfig.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
- "extends": [
3
- "../../../common/build/build-common/tsconfig.base.json",
4
- "../../../common/build/build-common/tsconfig.cjs.json",
5
- ],
2
+ "extends": "../../../common/build/build-common/tsconfig.node16.json",
6
3
  "include": ["src/**/*"],
7
4
  "exclude": ["src/test/**/*"],
8
5
  "compilerOptions": {
9
6
  "rootDir": "./src",
10
- "outDir": "./dist",
7
+ "outDir": "./lib",
11
8
  },
12
9
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.d.mts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC;AAExF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,sBAA0C,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACpD;;;;;;;;;;;;;;;;OAgBG;IACH,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,OAAE;CAC5E;AAED;;;GAGG;AACH,MAAM,WAAW,eAChB,SAAQ,sBAAsB,EAC7B,cAAc,CAAC,qBAAqB,CAAC,EACrC,cAAc;IACf;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;OAKG;IACH,OAAO,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,WAAW,IAAI,MAAM,EAAE,CAAC;CACxB"}
package/lib/agent.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.mjs","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAiC,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, IFluidLoadable } from \"@fluidframework/core-interfaces\";\n\n/**\n * @alpha\n */\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\n/**\n * @alpha\n */\nexport interface IProvideAgentScheduler {\n\treadonly IAgentScheduler: IAgentScheduler;\n}\n\n/**\n * Events emitted by {@link (IAgentScheduler:interface)}.\n * @alpha\n */\nexport interface IAgentSchedulerEvents extends IEvent {\n\t/**\n\t * Event when ownership of task changes\n\t * @param event - name of the event:\n\t *\n\t * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n\t * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n\t * automatically, unless release() is called\n\t *\n\t * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n\t * re-acquire the task, unless pick() is called.\n\t *\n\t * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n\t * Task will be picked up again by some connected client (this client will try as well,\n\t * unless release() is called)\n\t *\n\t * @param listener - callback notified when change happened for particular key\n\t */\n\t(event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n * @alpha\n */\nexport interface IAgentScheduler\n\textends IProvideAgentScheduler,\n\t\tIEventProvider<IAgentSchedulerEvents>,\n\t\tIFluidLoadable {\n\t/**\n\t * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n\t * a new agent to run but does not have the capability to run the agent inside the host.\n\t * Client can call pick() later if the capability changes.\n\t *\n\t * This method should only be called once per task. Duplicate calls will be rejected.\n\t */\n\tregister(...taskUrls: string[]): Promise<void>;\n\n\t/**\n\t * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n\t * Resolves when the tasks are assigned to one of the connected clients.\n\t *\n\t * This method should only be called once per task. Duplicate calls will be rejected.\n\t *\n\t * @param worker - callback to run when task is picked up.\n\t */\n\tpick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n\t/**\n\t * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n\t *\n\t * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n\t * App can call pickedTasks() to get the picked list first.\n\t */\n\trelease(...taskUrls: string[]): Promise<void>;\n\n\t/**\n\t * Returns a list of all tasks running on this client\n\t */\n\tpickedTasks(): string[];\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,eAAe,EAAE,qBAAqB,EAAE,sBAAsB,EAAE;OAClE,EAAE,qBAAqB,EAAE;OACzB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE"}
package/lib/index.mjs DELETED
@@ -1,8 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { IAgentScheduler } from "./agent.mjs";
6
- export { AgentSchedulerFactory } from "./scheduler.mjs";
7
- export { TaskSubscription } from "./taskSubscription.mjs";
8
- //# sourceMappingURL=index.mjs.map
package/lib/index.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,eAAe,EAAiD;OAClE,EAAE,qBAAqB,EAAE;OACzB,EAA2B,gBAAgB,EAAE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from \"./agent\";\nexport { AgentSchedulerFactory } from \"./scheduler\";\nexport { ITaskSubscriptionEvents, TaskSubscription } from \"./taskSubscription\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduler.d.mts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OAEzD,EAAe,YAAY,EAAY,MAAM,iCAAiC;OAC9E,EACN,qBAAqB,EAGrB,MAAM,2BAA2B;OAG3B,EAAE,2BAA2B,EAAE,MAAM,qCAAqC;OAC1E,EAAE,sBAAsB,EAAmB,MAAM,uCAAuC;OACxF,EACN,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EAChC,MAAM,qCAAqC;OAGrC,EAAE,eAAe,EAAE,qBAAqB,EAAE;AA4BjD,qBAAa,cACZ,SAAQ,iBAAiB,CAAC,qBAAqB,CAC/C,YAAW,eAAe;IAgEzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,2BAA2B;WAhEzB,IAAI,CACvB,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,OAAO;IAyBlB,IAAW,eAAe,SAEzB;IACD,IAAW,cAAc,SAExB;IAED,OAAO,KAAK,QAAQ,GAOnB;IAMD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAKrD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA0C;IAI/E,OAAO,CAAC,YAAY,CAAqB;IAEzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;gBAG3B,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,2BAA2B,EAAE,2BAA2B,CAAC,MAAM,GAAG,IAAI,CAAC;IAQzF,IAAW,MAAM,uBA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AC3C,SAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,IAAI,EAAE,kCAAkC,CAAC,CAAC;QAE3F,OAAO,IAAI,qBAAqB,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;;AAtCsB,0BAAI,GAAG,YAAY,AAAf,CAAgB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { FluidObject, IFluidHandle, IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tFluidDataStoreRuntime,\n\tFluidObjectHandle,\n\tISharedObjectRegistry,\n} from \"@fluidframework/datastore\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ISharedMap, IValueChanged, SharedMap } from \"@fluidframework/map\";\nimport { ConsensusRegisterCollection } from \"@fluidframework/register-collection\";\nimport { IFluidDataStoreRuntime, IChannelFactory } from \"@fluidframework/datastore-definitions\";\nimport {\n\tIFluidDataStoreContext,\n\tIFluidDataStoreFactory,\n\tNamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport { tagCodeArtifacts, UsageError } from \"@fluidframework/telemetry-utils\";\nimport { IAgentScheduler, IAgentSchedulerEvents } from \"./agent\";\n\n// Note: making sure this ID is unique and does not collide with storage provided clientID\nconst UnattachedClientId = `${uuid()}_unattached`;\n\nconst mapWait = async <T = any>(map: ISharedMap, key: string): Promise<T> => {\n\tconst maybeValue = map.get<T>(key);\n\tif (maybeValue !== undefined) {\n\t\treturn maybeValue;\n\t}\n\n\treturn new Promise((resolve) => {\n\t\tconst handler = (changed: IValueChanged) => {\n\t\t\tif (changed.key === key) {\n\t\t\t\tmap.off(\"valueChanged\", handler);\n\t\t\t\tconst value = map.get<T>(changed.key);\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tthrow new Error(\"Unexpected valueChanged result\");\n\t\t\t\t}\n\t\t\t\tresolve(value);\n\t\t\t}\n\t\t};\n\t\tmap.on(\"valueChanged\", handler);\n\t});\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n\textends TypedEventEmitter<IAgentSchedulerEvents>\n\timplements IAgentScheduler\n{\n\tpublic static async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t) {\n\t\tlet root: ISharedMap;\n\t\tlet consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n\t\tif (!existing) {\n\t\t\troot = SharedMap.create(runtime, \"root\");\n\t\t\troot.bindToContext();\n\t\t\tconsensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n\t\t\tconsensusRegisterCollection.bindToContext();\n\t\t\troot.set(schedulerId, consensusRegisterCollection.handle);\n\t\t} else {\n\t\t\troot = (await runtime.getChannel(\"root\")) as ISharedMap;\n\t\t\tconst handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(\n\t\t\t\troot,\n\t\t\t\tschedulerId,\n\t\t\t);\n\t\t\tassert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n\t\t\tconsensusRegisterCollection = await handle.get();\n\t\t}\n\t\tconst agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n\t\tagentScheduler.initialize();\n\n\t\treturn agentScheduler;\n\t}\n\n\tpublic get IAgentScheduler() {\n\t\treturn this;\n\t}\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate get clientId(): string {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn UnattachedClientId;\n\t\t}\n\t\tconst clientId = this.runtime.clientId;\n\t\tassert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n\t\treturn clientId;\n\t}\n\n\t// Set of tasks registered by this client.\n\t// Has no relationship with lists below.\n\t// The only requirement here - a task can be registered by a client only once.\n\t// Other clients can pick these tasks.\n\tprivate readonly registeredTasks = new Set<string>();\n\n\t// List of all tasks client is capable of running (essentially expressed desire to run)\n\t// Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n\t// This is a strict superset of tasks running in the client.\n\tprivate readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n\t// Set of registered tasks client is currently running.\n\t// It's subset of this.locallyRunnableTasks\n\tprivate runningTasks = new Set<string>();\n\n\tprivate readonly _handle: IFluidHandle<this>;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\t\tprivate readonly context: IFluidDataStoreContext,\n\t\tprivate readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n\t) {\n\t\tsuper();\n\t\t// We are expecting this class to have many listeners, so we suppress noisy \"MaxListenersExceededWarning\" logging.\n\t\tsuper.setMaxListeners(0);\n\t\tthis._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n\t}\n\n\tpublic get handle() {\n\t\treturn this._handle;\n\t}\n\n\tpublic async register(...taskUrls: string[]): Promise<void> {\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (this.registeredTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task is already registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\tconst unregisteredTasks: string[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tthis.registeredTasks.add(taskUrl);\n\t\t\t// Only register for a new task.\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined) {\n\t\t\t\tunregisteredTasks.push(taskUrl);\n\t\t\t}\n\t\t}\n\t\treturn this.registerCore(unregisteredTasks);\n\t}\n\n\tpublic async pick(taskUrl: string, worker: () => Promise<void>): Promise<void> {\n\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\tthrow new UsageError(`Task is already attempted`, tagCodeArtifacts({ taskUrl }));\n\t\t}\n\t\tthis.locallyRunnableTasks.set(taskUrl, worker);\n\n\t\t// We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n\t\t// either perform this check proactively and call conditionally, or catch the error (in which case\n\t\t// they can know they will not get the task).\n\t\tassert(\n\t\t\tthis.context.deltaManager.clientDetails.capabilities.interactive,\n\t\t\t0x118 /* \"Bad client interactive check\" */,\n\t\t);\n\n\t\t// Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n\t\tif (this.isActive()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient === undefined || currentClient === null) {\n\t\t\t\tawait this.writeCore(taskUrl, this.clientId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async release(...taskUrls: string[]): Promise<void> {\n\t\tconst active = this.isActive();\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tif (!this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\tthrow new UsageError(`Task was never registered`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\tif (!this.runningTasks.has(taskUrl)) {\n\t\t\t\t// If we got disconnected (and are attached), tasks that we WERE picked for at the time of disconnect\n\t\t\t\t// will still show us as holding the task according to getTaskClientId (the CRC is stale), but we\n\t\t\t\t// should not try to release because our disconnect will already result in either someone else or\n\t\t\t\t// ourselves clearing the task upon reconnect.\n\t\t\t\t// This UsageError is to enforce that the caller should check AgentScheduler.pickedTasks before trying\n\t\t\t\t// to release a task.\n\t\t\t\tthrow new UsageError(`Task is not currently picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t\t// We may only release tasks that we KNOW we hold (detached state or connected and own the CRC). If we're\n\t\t\t// attached+disconnected then we'll lose the task automatically, and so may not release manually (someone\n\t\t\t// else might hold it by the time we reconnect)\n\t\t\tassert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n\t\t\tif (this.getTaskClientId(taskUrl) !== this.clientId) {\n\t\t\t\tthrow new UsageError(`Task was never picked`, tagCodeArtifacts({ taskUrl }));\n\t\t\t}\n\t\t}\n\t\treturn this.releaseCore([...taskUrls]);\n\t}\n\n\tpublic pickedTasks(): string[] {\n\t\treturn Array.from(this.runningTasks.values());\n\t}\n\n\tprivate async registerCore(taskUrls: string[]): Promise<void> {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst registersP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tregistersP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(registersP);\n\n\t\t\t// The registers should have up to date results now. Check the status.\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\tconst taskStatus = this.getTaskClientId(taskUrl);\n\n\t\t\t\t// Task should be either registered (null) or picked up.\n\t\t\t\tassert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async releaseCore(taskUrls: string[]) {\n\t\tif (taskUrls.length > 0) {\n\t\t\tconst releasesP: Promise<void>[] = [];\n\t\t\tfor (const taskUrl of taskUrls) {\n\t\t\t\t// Remove from local map so that it can be picked later.\n\t\t\t\tthis.locallyRunnableTasks.delete(taskUrl);\n\t\t\t\treleasesP.push(this.writeCore(taskUrl, null));\n\t\t\t}\n\t\t\tawait Promise.all(releasesP);\n\t\t}\n\t}\n\n\tprivate async clearTasks(taskUrls: string[]) {\n\t\tassert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n\t\tconst clearP: Promise<void>[] = [];\n\t\tfor (const taskUrl of taskUrls) {\n\t\t\tclearP.push(this.writeCore(taskUrl, null));\n\t\t}\n\t\tawait Promise.all(clearP);\n\t}\n\n\tprivate getTaskClientId(url: string): string | null | undefined {\n\t\treturn this.consensusRegisterCollection.read(url);\n\t}\n\n\tprivate async writeCore(key: string, clientId: string | null): Promise<void> {\n\t\tawait this.consensusRegisterCollection.write(key, clientId);\n\t}\n\n\tprivate initialize() {\n\t\tconst quorum = this.runtime.getQuorum();\n\t\t// A client left the quorum. Iterate and clear tasks held by that client.\n\t\t// Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n\t\t// Probably okay for now to have every client try to do this.\n\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\tquorum.on(\"removeMember\", async (clientId: string) => {\n\t\t\tassert(\n\t\t\t\tthis.runtime.objectsRoutingContext.isAttached,\n\t\t\t\t0x11c /* \"Detached object routing context\" */,\n\t\t\t);\n\t\t\t// Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n\t\t\tif (this.isActive()) {\n\t\t\t\tconst tasks: Promise<any>[] = [];\n\t\t\t\tconst leftTasks: string[] = [];\n\t\t\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\t\t\tif (this.getTaskClientId(taskUrl) === clientId) {\n\t\t\t\t\t\tif (this.locallyRunnableTasks.has(taskUrl)) {\n\t\t\t\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tleftTasks.push(taskUrl);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttasks.push(this.clearTasks(leftTasks));\n\t\t\t\tawait Promise.all(tasks).catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// Listeners for new/released tasks. All clients will try to grab at the same time.\n\t\t// May be we want a randomized timer (Something like raft) to reduce chattiness?\n\t\tthis.consensusRegisterCollection.on(\n\t\t\t\"atomicChanged\",\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\t\t\tasync (key: string, currentClient: string | null) => {\n\t\t\t\t// Check if this client was chosen.\n\t\t\t\tif (this.isActive() && currentClient === this.clientId) {\n\t\t\t\t\tthis.onNewTaskAssigned(key);\n\t\t\t\t} else {\n\t\t\t\t\t// The call below mutates the consensusRegisterCollection in\n\t\t\t\t\t// its event handler, which is not safe.\n\t\t\t\t\t// We need to force this to be part of a different batch of ops by\n\t\t\t\t\t// scheduling a microtask in order to work around the current validations.\n\t\t\t\t\t// This is not recommended and should be avoided.\n\t\t\t\t\tawait Promise.resolve().then(async () => {\n\t\t\t\t\t\tawait this.onTaskReassigned(key, currentClient);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tif (this.isActive()) {\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tthis.runtime.on(\"connected\", () => {\n\t\t\tif (this.isActive()) {\n\t\t\t\tthis.initializeCore();\n\t\t\t}\n\t\t});\n\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tthis.runtime\n\t\t\t\t.waitAttached()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.clearRunningTasks();\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n\t\t\t\t});\n\t\t}\n\n\t\tthis.runtime.on(\"disconnected\", () => {\n\t\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t\tthis.clearRunningTasks();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate onNewTaskAssigned(key: string) {\n\t\tassert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n\t\tthis.runningTasks.add(key);\n\t\tconst worker = this.locallyRunnableTasks.get(key);\n\t\tif (worker === undefined) {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n\t\t} else {\n\t\t\tthis.emit(\"picked\", key);\n\t\t\tworker().catch((error) => {\n\t\t\t\tthis.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async onTaskReassigned(key: string, currentClient: string | null) {\n\t\tif (this.runningTasks.has(key)) {\n\t\t\tthis.runningTasks.delete(key);\n\t\t\tthis.emit(\"released\", key);\n\t\t}\n\t\tassert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n\t\tif (this.isActive()) {\n\t\t\t// attempt to pick up task if we are connected.\n\t\t\t// If not, initializeCore() will do it when connected\n\t\t\tif (currentClient === null) {\n\t\t\t\tif (this.locallyRunnableTasks.has(key)) {\n\t\t\t\t\tawait this.writeCore(key, this.clientId);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Check if the op came from dropped client\n\t\t\t// This could happen when \"old\" ops are submitted on reconnection.\n\t\t\t// They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n\t\t\telse if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tawait this.writeCore(key, null);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isActive() {\n\t\t// Scheduler should be active in detached container.\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn true;\n\t\t}\n\t\tif (!this.runtime.connected) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n\t\t// here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n\t\treturn this.context.deltaManager.active;\n\t}\n\n\tprivate initializeCore() {\n\t\t// Nobody released the tasks held by last client in previous session.\n\t\t// Check to see if this client needs to do this.\n\t\tconst clearCandidates: string[] = [];\n\t\tconst tasks: Promise<any>[] = [];\n\n\t\tfor (const [taskUrl] of this.locallyRunnableTasks) {\n\t\t\tif (!this.getTaskClientId(taskUrl)) {\n\t\t\t\ttasks.push(this.writeCore(taskUrl, this.clientId));\n\t\t\t}\n\t\t}\n\n\t\tfor (const taskUrl of this.consensusRegisterCollection.keys()) {\n\t\t\tconst currentClient = this.getTaskClientId(taskUrl);\n\t\t\tif (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n\t\t\t\tclearCandidates.push(taskUrl);\n\t\t\t}\n\t\t}\n\n\t\ttasks.push(this.clearTasks(clearCandidates));\n\n\t\tPromise.all(tasks).catch((error) => {\n\t\t\tthis.sendErrorEvent(\"AgentScheduler_InitError\", error);\n\t\t});\n\t}\n\n\tprivate clearRunningTasks() {\n\t\tconst tasks = this.runningTasks;\n\t\tthis.runningTasks = new Set<string>();\n\n\t\tif (this.isActive()) {\n\t\t\t// Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n\t\t\t// If we are simply disconnected, then proper cleanup will be done on connection.\n\t\t\tthis.initializeCore();\n\t\t}\n\n\t\tfor (const task of tasks) {\n\t\t\tthis.emit(\"lost\", task);\n\t\t}\n\t}\n\n\tprivate sendErrorEvent(eventName: string, error: any, key?: string) {\n\t\tthis.runtime.logger.sendErrorEvent({ eventName, key }, error);\n\t}\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n\tconstructor(\n\t\tdataStoreContext: IFluidDataStoreContext,\n\t\tsharedObjectRegistry: ISharedObjectRegistry,\n\t\texisting: boolean,\n\t) {\n\t\tsuper(dataStoreContext, sharedObjectRegistry, existing, async () =>\n\t\t\tAgentScheduler.load(this, dataStoreContext, existing),\n\t\t);\n\t}\n\tpublic async request(request: IRequest) {\n\t\tconst response = await super.request(request);\n\t\tif (response.status === 404) {\n\t\t\tif (request.url === \"\" || request.url === \"/\") {\n\t\t\t\tconst agentScheduler = await this.entryPoint.get();\n\t\t\t\tassert(\n\t\t\t\t\tagentScheduler !== undefined,\n\t\t\t\t\t0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */,\n\t\t\t\t);\n\n\t\t\t\treturn { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n\t\t\t}\n\t\t}\n\t\treturn response;\n\t}\n}\n\n/**\n * @alpha\n */\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n\tpublic static readonly type = \"_scheduler\";\n\tpublic readonly type = AgentSchedulerFactory.type;\n\n\tpublic get IFluidDataStoreFactory() {\n\t\treturn this;\n\t}\n\n\tpublic static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n\t\treturn [this.type, Promise.resolve(new AgentSchedulerFactory())];\n\t}\n\n\tpublic static async createChildInstance(\n\t\tparentContext: IFluidDataStoreContext,\n\t): Promise<IAgentScheduler> {\n\t\tconst packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n\t\tconst dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n\t\tconst entryPoint: FluidObject<IAgentScheduler> = await dataStore.entryPoint.get();\n\n\t\t// AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n\t\t// while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n\t\tassert(\n\t\t\tentryPoint.IAgentScheduler !== undefined,\n\t\t\t0x467 /* The data store's entryPoint is not an AgentScheduler! */,\n\t\t);\n\t\treturn entryPoint as unknown as AgentScheduler;\n\t}\n\n\tpublic async instantiateDataStore(\n\t\tcontext: IFluidDataStoreContext,\n\t\texisting: boolean,\n\t): Promise<FluidDataStoreRuntime> {\n\t\tconst mapFactory = SharedMap.getFactory();\n\t\tconst consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n\t\tconst dataTypes = new Map<string, IChannelFactory>();\n\t\tdataTypes.set(mapFactory.type, mapFactory);\n\t\tdataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n\t\treturn new AgentSchedulerRuntime(context, dataTypes, existing);\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"taskSubscription.d.mts","sourceRoot":"","sources":["../src/taskSubscription.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,MAAM,EAAE,MAAM,iCAAiC;OACjD,EAAE,iBAAiB,EAAE,MAAM,8BAA8B;OACzD,EAAE,eAAe,EAAE;AAE1B;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,MAAM;IACtD,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CACtD;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,uBAAuB,CAAC;IAQ9E,OAAO,CAAC,QAAQ,CAAC,cAAc;aACf,MA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IAAI,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,uFAAuF;YACvF,gFAAgF;YAChF,0FAA0F;YAC1F,qCAAqC;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACtE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACvB;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IAgentScheduler } from \"./agent\";\n\n/**\n * Events emitted by {@link TaskSubscription}.\n * @alpha\n */\nexport interface ITaskSubscriptionEvents extends IEvent {\n\t(event: \"gotTask\" | \"lostTask\", listener: () => void);\n}\n\n/**\n * TaskSubscription works with an AgentScheduler to make it easier to monitor a specific task ownership.\n * @alpha\n */\nexport class TaskSubscription extends TypedEventEmitter<ITaskSubscriptionEvents> {\n\tprivate subscribed: boolean = false;\n\n\t/**\n\t * @param agentScheduler - The AgentScheduler that will be subscribed against\n\t * @param taskId - The string ID of the task to subscribe against\n\t */\n\tconstructor(\n\t\tprivate readonly agentScheduler: IAgentScheduler,\n\t\tpublic readonly taskId: string,\n\t) {\n\t\tsuper();\n\t\tagentScheduler.on(\"picked\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"gotTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"released\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t\tagentScheduler.on(\"lost\", (_taskId: string) => {\n\t\t\tif (_taskId === this.taskId) {\n\t\t\t\tthis.emit(\"lostTask\");\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Check if currently holding ownership of the task.\n\t * @returns true if currently the task owner, false otherwise.\n\t */\n\tpublic haveTask() {\n\t\treturn this.agentScheduler.pickedTasks().includes(this.taskId);\n\t}\n\n\t/**\n\t * Volunteer for the task. By default, the TaskSubscription will only watch the task and not volunteer.\n\t * This is safe to call multiple times across multiple TaskSubscriptions.\n\t */\n\tpublic volunteer() {\n\t\tif (!this.subscribed) {\n\t\t\t// AgentScheduler throws if the same task is picked twice but we don't care because our\n\t\t\t// worker does nothing. We only care that the AgentScheduler is trying to pick.\n\t\t\t// We also don't care if we throw due to failing the interactive check, because then we'll\n\t\t\t// just appear to never get the task.\n\t\t\tthis.agentScheduler.pick(this.taskId, async () => {}).catch(() => {});\n\t\t\tthis.subscribed = true;\n\t\t}\n\t}\n}\n"]}