@fluidframework/agent-scheduler 2.0.0-internal.2.0.2 → 2.0.0-internal.2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
6
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
6
7
  export declare const IAgentScheduler: keyof IProvideAgentScheduler;
7
8
  export interface IProvideAgentScheduler {
8
9
  readonly IAgentScheduler: IAgentScheduler;
@@ -30,7 +31,7 @@ export interface IAgentSchedulerEvents extends IEvent {
30
31
  /**
31
32
  * Agent scheduler distributes a set of tasks/variables across connected clients.
32
33
  */
33
- export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents> {
34
+ export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents>, IFluidLoadable {
34
35
  /**
35
36
  * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants
36
37
  * a new agent to run but does not have the capability to run the agent inside the host.
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAE5E,eAAO,MAAM,eAAe,EAAE,MAAM,sBAA0C,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC7C;AAED,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACjD;;;;;;;;;;;;;;;;OAgBG;IACH,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,OAAE;CAC/E;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB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,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;CAC3B"}
package/dist/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIU,QAAA,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 } from \"@fluidframework/common-definitions\";\n\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\nexport interface IProvideAgentScheduler {\n readonly IAgentScheduler: IAgentScheduler;\n}\n\nexport interface IAgentSchedulerEvents extends IEvent {\n /**\n * Event when ownership of task changes\n * @param event - name of the event:\n *\n * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n * automatically, unless release() is called\n *\n * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n * re-acquire the task, unless pick() is called.\n *\n * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n * Task will be picked up again by some connected client (this client will try as well,\n * unless release() is called)\n *\n * @param listener - callback notified when change happened for particular key\n */\n (event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n */\nexport interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents> {\n /**\n * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n * a new agent to run but does not have the capability to run the agent inside the host.\n * Client can call pick() later if the capability changes.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n */\n register(...taskUrls: string[]): Promise<void>;\n\n /**\n * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n * Resolves when the tasks are assigned to one of the connected clients.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n *\n * @param worker - callback to run when task is picked up.\n */\n pick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n /**\n * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n *\n * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n * App can call pickedTasks() to get the picked list first.\n */\n release(...taskUrls: string[]): Promise<void>;\n\n /**\n * Returns a list of all tasks running on this client\n */\n pickedTasks(): string[];\n}\n"]}
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKU,QAAA,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 } from \"@fluidframework/common-definitions\";\nimport { IFluidLoadable } from \"@fluidframework/core-interfaces\";\n\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\nexport interface IProvideAgentScheduler {\n readonly IAgentScheduler: IAgentScheduler;\n}\n\nexport interface IAgentSchedulerEvents extends IEvent {\n /**\n * Event when ownership of task changes\n * @param event - name of the event:\n *\n * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n * automatically, unless release() is called\n *\n * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n * re-acquire the task, unless pick() is called.\n *\n * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n * Task will be picked up again by some connected client (this client will try as well,\n * unless release() is called)\n *\n * @param listener - callback notified when change happened for particular key\n */\n (event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n */\nexport interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents>, IFluidLoadable {\n /**\n * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n * a new agent to run but does not have the capability to run the agent inside the host.\n * Client can call pick() later if the capability changes.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n */\n register(...taskUrls: string[]): Promise<void>;\n\n /**\n * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n * Resolves when the tasks are assigned to one of the connected clients.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n *\n * @param worker - callback to run when task is picked up.\n */\n pick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n /**\n * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n *\n * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n * App can call pickedTasks() to get the picked list first.\n */\n release(...taskUrls: string[]): Promise<void>;\n\n /**\n * Returns a list of all tasks running on this client\n */\n pickedTasks(): string[];\n}\n"]}
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 * from "./agent";
5
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent";
6
6
  export { AgentSchedulerFactory } from "./scheduler";
7
- export * from "./taskSubscription";
7
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription";
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,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc,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,SAAS,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -3,20 +3,12 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
6
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AgentSchedulerFactory = void 0;
18
- __exportStar(require("./agent"), exports);
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; } });
19
10
  var scheduler_1 = require("./scheduler");
20
11
  Object.defineProperty(exports, "AgentSchedulerFactory", { enumerable: true, get: function () { return scheduler_1.AgentSchedulerFactory; } });
21
- __exportStar(require("./taskSubscription"), exports);
12
+ var taskSubscription_1 = require("./taskSubscription");
13
+ Object.defineProperty(exports, "TaskSubscription", { enumerable: true, get: function () { return taskSubscription_1.TaskSubscription; } });
22
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,0CAAwB;AACxB,yCAAoD;AAA3C,kHAAA,qBAAqB,OAAA;AAC9B,qDAAmC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./agent\";\nexport { AgentSchedulerFactory } from \"./scheduler\";\nexport * from \"./taskSubscription\";\n"]}
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"]}
@@ -3,13 +3,13 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { TypedEventEmitter } from "@fluidframework/common-utils";
6
- import { IFluidHandle, IFluidLoadable, IRequest } from "@fluidframework/core-interfaces";
6
+ import { IFluidHandle, IRequest } from "@fluidframework/core-interfaces";
7
7
  import { FluidDataStoreRuntime, ISharedObjectRegistry } 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
11
  import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
12
- export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler, IFluidLoadable {
12
+ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {
13
13
  private readonly runtime;
14
14
  private readonly context;
15
15
  private readonly consensusRegisterCollection;
@@ -41,7 +41,6 @@ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEve
41
41
  private sendErrorEvent;
42
42
  }
43
43
  declare class AgentSchedulerRuntime extends FluidDataStoreRuntime {
44
- private readonly agentSchedulerP;
45
44
  constructor(dataStoreContext: IFluidDataStoreContext, sharedObjectRegistry: ISharedObjectRegistry, existing: boolean);
46
45
  request(request: IRequest): Promise<import("@fluidframework/core-interfaces").IResponse>;
47
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACH,YAAY,EACZ,cAAc,EACd,QAAQ,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,qBAAqB,EAErB,qBAAqB,EACxB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uCAAuC,CAAC;AAChG,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EACnC,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA4BjE,qBAAa,cACT,SAAQ,iBAAiB,CAAC,qBAAqB,CAC/C,YAAW,eAAe,EAAE,cAAc;IAqDtC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,2BAA2B;WArD5B,IAAI,CAAC,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,OAAO;IAqB5G,IAAW,eAAe,SAAmB;IAC7C,IAAW,cAAc,SAAmB;IAE5C,OAAO,KAAK,QAAQ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ore_1 = require("@fluidframework/datastore");
10
10
  const container_definitions_1 = require("@fluidframework/container-definitions");
11
11
  const map_1 = require("@fluidframework/map");
12
12
  const register_collection_1 = require("@fluidframework/register-collection");
13
- const runtime_utils_1 = require("@fluidframework/runtime-utils");
14
13
  const uuid_1 = require("uuid");
15
14
  // Note: making sure this ID is unique and does not collide with storage provided clientID
16
15
  const UnattachedClientId = `${(0, uuid_1.v4)()}_unattached`;
@@ -330,14 +329,15 @@ class AgentScheduler extends common_utils_1.TypedEventEmitter {
330
329
  exports.AgentScheduler = AgentScheduler;
331
330
  class AgentSchedulerRuntime extends datastore_1.FluidDataStoreRuntime {
332
331
  constructor(dataStoreContext, sharedObjectRegistry, existing) {
333
- super(dataStoreContext, sharedObjectRegistry, existing);
334
- this.agentSchedulerP = AgentScheduler.load(this, dataStoreContext, existing);
332
+ super(dataStoreContext, sharedObjectRegistry, existing, async () => AgentScheduler.load(this, dataStoreContext, existing));
335
333
  }
336
334
  async request(request) {
335
+ var _a;
337
336
  const response = await super.request(request);
338
337
  if (response.status === 404) {
339
338
  if (request.url === "" || request.url === "/") {
340
- const agentScheduler = await this.agentSchedulerP;
339
+ const agentScheduler = await ((_a = this.entryPoint) === null || _a === void 0 ? void 0 : _a.get());
340
+ (0, common_utils_1.assert)(agentScheduler !== undefined, 0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */);
341
341
  return { status: 200, mimeType: "fluid/object", value: agentScheduler };
342
342
  }
343
343
  }
@@ -353,9 +353,14 @@ class AgentSchedulerFactory {
353
353
  return [this.type, Promise.resolve(new AgentSchedulerFactory())];
354
354
  }
355
355
  static async createChildInstance(parentContext) {
356
+ var _a;
356
357
  const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];
357
- const router = await parentContext.containerRuntime.createDataStore(packagePath);
358
- return (0, runtime_utils_1.requestFluidObject)(router, "/");
358
+ const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);
359
+ const entryPoint = await ((_a = dataStore.entryPoint) === null || _a === void 0 ? void 0 : _a.get());
360
+ // AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check
361
+ // while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.
362
+ (0, common_utils_1.assert)((entryPoint === null || entryPoint === void 0 ? void 0 : entryPoint.IAgentScheduler) !== undefined, 0x467 /* The data store's entryPoint is not an AgentScheduler! */);
363
+ return entryPoint;
359
364
  }
360
365
  async instantiateDataStore(context, existing) {
361
366
  const mapFactory = map_1.SharedMap.getFactory();
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAyE;AAMzE,yDAImC;AACnC,iFAAoE;AACpE,6CAA2E;AAC3E,6EAAkF;AAOlF,iEAAmE;AACnE,+BAAkC;AAGlC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAA,SAAI,GAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,EAAW,GAAe,EAAE,GAAW,EAAc,EAAE;IACxE,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;IACnC,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,OAAO,UAAU,CAAC;KACrB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,MAAM,OAAO,GAAG,CAAC,OAAsB,EAAE,EAAE;YACvC,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,EAAE;gBACrB,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;gBACjC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAI,OAAO,CAAC,GAAG,CAAC,CAAC;gBACtC,IAAI,KAAK,KAAK,SAAS,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;iBACrD;gBACD,OAAO,CAAC,KAAK,CAAC,CAAC;aAClB;Q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AAC;IArBG,IAAW,sBAAsB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAE7C,MAAM,KAAK,aAAa;QAC3B,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,aAAqC;QACzE,MAAM,WAAW,GAAG,CAAC,GAAG,aAAa,CAAC,WAAW,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACjF,OAAO,IAAA,kCAAkB,EAAiB,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,OAA+B,EAAE,QAAiB;QAChF,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;IACnE,CAAC;;AAxBL,sDAyBC;AAxB0B,0BAAI,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n IFluidHandle,\n IFluidLoadable,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport {\n FluidDataStoreRuntime,\n FluidObjectHandle,\n ISharedObjectRegistry,\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 IFluidDataStoreContext,\n IFluidDataStoreFactory,\n NamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\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 const maybeValue = map.get<T>(key);\n if (maybeValue !== undefined) {\n return maybeValue;\n }\n\n return new Promise((resolve) => {\n const handler = (changed: IValueChanged) => {\n if (changed.key === key) {\n map.off(\"valueChanged\", handler);\n const value = map.get<T>(changed.key);\n if (value === undefined) {\n throw new Error(\"Unexpected valueChanged result\");\n }\n resolve(value);\n }\n };\n map.on(\"valueChanged\", handler);\n });\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n extends TypedEventEmitter<IAgentSchedulerEvents>\n implements IAgentScheduler, IFluidLoadable\n{ // eslint-disable-line @typescript-eslint/brace-style\n public static async load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean) {\n let root: ISharedMap;\n let consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n if (!existing) {\n root = SharedMap.create(runtime, \"root\");\n root.bindToContext();\n consensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n consensusRegisterCollection.bindToContext();\n root.set(schedulerId, consensusRegisterCollection.handle);\n } else {\n root = await runtime.getChannel(\"root\") as ISharedMap;\n const handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(root, schedulerId);\n assert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n consensusRegisterCollection = await handle.get();\n }\n const agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n agentScheduler.initialize();\n\n return agentScheduler;\n }\n\n public get IAgentScheduler() { return this; }\n public get IFluidLoadable() { return this; }\n\n private get clientId(): string {\n if (this.runtime.attachState === AttachState.Detached) {\n return UnattachedClientId;\n }\n const clientId = this.runtime.clientId;\n assert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n return clientId;\n }\n\n // Set of tasks registered by this client.\n // Has no relationship with lists below.\n // The only requirement here - a task can be registered by a client only once.\n // Other clients can pick these tasks.\n private readonly registeredTasks = new Set<string>();\n\n // List of all tasks client is capable of running (essentially expressed desire to run)\n // Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n // This is a strict superset of tasks running in the client.\n private readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n // Set of registered tasks client is currently running.\n // It's subset of this.locallyRunnableTasks\n private runningTasks = new Set<string>();\n\n private readonly _handle: IFluidHandle<this>;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly context: IFluidDataStoreContext,\n private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n ) {\n super();\n this._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n }\n\n public get handle() {\n return this._handle;\n }\n\n public async register(...taskUrls: string[]): Promise<void> {\n for (const taskUrl of taskUrls) {\n if (this.registeredTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} is already registered`);\n }\n }\n const unregisteredTasks: string[] = [];\n for (const taskUrl of taskUrls) {\n this.registeredTasks.add(taskUrl);\n // Only register for a new task.\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient === undefined) {\n unregisteredTasks.push(taskUrl);\n }\n }\n return this.registerCore(unregisteredTasks);\n }\n\n public async pick(taskId: string, worker: () => Promise<void>): Promise<void> {\n if (this.locallyRunnableTasks.has(taskId)) {\n throw new Error(`${taskId} is already attempted`);\n }\n this.locallyRunnableTasks.set(taskId, worker);\n\n // We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n // either perform this check proactively and call conditionally, or catch the error (in which case\n // they can know they will not get the task).\n assert(this.context.deltaManager.clientDetails.capabilities.interactive,\n 0x118 /* \"Bad client interactive check\" */);\n\n // Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n if (this.isActive()) {\n const currentClient = this.getTaskClientId(taskId);\n if (currentClient === undefined || currentClient === null) {\n await this.writeCore(taskId, this.clientId);\n }\n }\n }\n\n public async release(...taskUrls: string[]): Promise<void> {\n const active = this.isActive();\n for (const taskUrl of taskUrls) {\n if (!this.locallyRunnableTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} was never registered`);\n }\n // Note - the assumption is - we are connected.\n // If not - all tasks should have been dropped already on disconnect / attachment\n assert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n if (this.getTaskClientId(taskUrl) !== this.clientId) {\n throw new Error(`${taskUrl} was never picked`);\n }\n }\n return this.releaseCore([...taskUrls]);\n }\n\n public pickedTasks(): string[] {\n return Array.from(this.runningTasks.values());\n }\n\n private async registerCore(taskUrls: string[]): Promise<void> {\n if (taskUrls.length > 0) {\n const registersP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n registersP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(registersP);\n\n // The registers should have up to date results now. Check the status.\n for (const taskUrl of taskUrls) {\n const taskStatus = this.getTaskClientId(taskUrl);\n\n // Task should be either registered (null) or picked up.\n assert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n }\n }\n }\n\n private async releaseCore(taskUrls: string[]) {\n if (taskUrls.length > 0) {\n const releasesP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n // Remove from local map so that it can be picked later.\n this.locallyRunnableTasks.delete(taskUrl);\n releasesP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(releasesP);\n }\n }\n\n private async clearTasks(taskUrls: string[]) {\n assert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n const clearP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n clearP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(clearP);\n }\n\n private getTaskClientId(url: string): string | null | undefined {\n return this.consensusRegisterCollection.read(url);\n }\n\n private async writeCore(key: string, clientId: string | null): Promise<void> {\n await this.consensusRegisterCollection.write(key, clientId);\n }\n\n private initialize() {\n const quorum = this.runtime.getQuorum();\n // A client left the quorum. Iterate and clear tasks held by that client.\n // Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n // Probably okay for now to have every client try to do this.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n quorum.on(\"removeMember\", async (clientId: string) => {\n assert(this.runtime.objectsRoutingContext.isAttached, 0x11c /* \"Detached object routing context\" */);\n // Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n if (this.isActive()) {\n const tasks: Promise<any>[] = [];\n const leftTasks: string[] = [];\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n if (this.getTaskClientId(taskUrl) === clientId) {\n if (this.locallyRunnableTasks.has(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n } else {\n leftTasks.push(taskUrl);\n }\n }\n }\n tasks.push(this.clearTasks(leftTasks));\n await Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n });\n }\n });\n\n // Listeners for new/released tasks. All clients will try to grab at the same time.\n // May be we want a randomized timer (Something like raft) to reduce chattiness?\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.consensusRegisterCollection.on(\"atomicChanged\", async (key: string, currentClient: string | null) => {\n // Check if this client was chosen.\n if (this.isActive() && currentClient === this.clientId) {\n this.onNewTaskAssigned(key);\n } else {\n await this.onTaskReassigned(key, currentClient);\n }\n });\n\n if (this.isActive()) {\n this.initializeCore();\n }\n\n this.runtime.on(\"connected\", () => {\n if (this.isActive()) {\n this.initializeCore();\n }\n });\n\n if (this.runtime.attachState === AttachState.Detached) {\n this.runtime.waitAttached().then(() => {\n this.clearRunningTasks();\n }).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n });\n }\n\n this.runtime.on(\"disconnected\", () => {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.clearRunningTasks();\n }\n });\n }\n\n private onNewTaskAssigned(key: string) {\n assert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n this.runningTasks.add(key);\n const worker = this.locallyRunnableTasks.get(key);\n if (worker === undefined) {\n this.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n } else {\n this.emit(\"picked\", key);\n worker().catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n });\n }\n }\n\n private async onTaskReassigned(key: string, currentClient: string | null) {\n if (this.runningTasks.has(key)) {\n this.runningTasks.delete(key);\n this.emit(\"released\", key);\n }\n assert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n /* eslint-disable @typescript-eslint/brace-style */\n if (this.isActive()) {\n // attempt to pick up task if we are connected.\n // If not, initializeCore() will do it when connected\n if (currentClient === null) {\n if (this.locallyRunnableTasks.has(key)) {\n await this.writeCore(key, this.clientId);\n }\n }\n // Check if the op came from dropped client\n // This could happen when \"old\" ops are submitted on reconnection.\n // They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n else if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n await this.writeCore(key, null);\n }\n }\n /* eslint-enable @typescript-eslint/brace-style */\n }\n\n private isActive() {\n // Scheduler should be active in detached container.\n if (this.runtime.attachState === AttachState.Detached) {\n return true;\n }\n if (!this.runtime.connected) {\n return false;\n }\n\n // Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n // here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n return this.context.deltaManager.active;\n }\n\n private initializeCore() {\n // Nobody released the tasks held by last client in previous session.\n // Check to see if this client needs to do this.\n const clearCandidates: string[] = [];\n const tasks: Promise<any>[] = [];\n\n for (const [taskUrl] of this.locallyRunnableTasks) {\n if (!this.getTaskClientId(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n }\n }\n\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n clearCandidates.push(taskUrl);\n }\n }\n\n tasks.push(this.clearTasks(clearCandidates));\n\n Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_InitError\", error);\n });\n }\n\n private clearRunningTasks() {\n const tasks = this.runningTasks;\n this.runningTasks = new Set<string>();\n\n if (this.isActive()) {\n // Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n // If we are simply disconnected, then proper cleanup will be done on connection.\n this.initializeCore();\n }\n\n for (const task of tasks) {\n this.emit(\"lost\", task);\n }\n }\n\n private sendErrorEvent(eventName: string, error: any, key?: string) {\n this.runtime.logger.sendErrorEvent({ eventName, key }, error);\n }\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n private readonly agentSchedulerP: Promise<AgentScheduler>;\n constructor(\n dataStoreContext: IFluidDataStoreContext,\n sharedObjectRegistry: ISharedObjectRegistry,\n existing: boolean,\n ) {\n super(dataStoreContext, sharedObjectRegistry, existing);\n this.agentSchedulerP = AgentScheduler.load(this, dataStoreContext, existing);\n }\n public async request(request: IRequest) {\n const response = await super.request(request);\n if (response.status === 404) {\n if (request.url === \"\" || request.url === \"/\") {\n const agentScheduler = await this.agentSchedulerP;\n return { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n }\n }\n return response;\n }\n}\n\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n public static readonly type = \"_scheduler\";\n public readonly type = AgentSchedulerFactory.type;\n\n public get IFluidDataStoreFactory() { return this; }\n\n public static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n return [this.type, Promise.resolve(new AgentSchedulerFactory())];\n }\n\n public static async createChildInstance(parentContext: IFluidDataStoreContext): Promise<AgentScheduler> {\n const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n const router = await parentContext.containerRuntime.createDataStore(packagePath);\n return requestFluidObject<AgentScheduler>(router, \"/\");\n }\n\n public async instantiateDataStore(context: IFluidDataStoreContext, existing: boolean) {\n const mapFactory = SharedMap.getFactory();\n const consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n const dataTypes = new Map<string, IChannelFactory>();\n dataTypes.set(mapFactory.type, mapFactory);\n dataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n return new AgentSchedulerRuntime(context, dataTypes, existing);\n }\n}\n"]}
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAyE;AAMzE,yDAImC;AACnC,iFAAoE;AACpE,6CAA2E;AAC3E,6EAAkF;AAOlF,+BAAkC;AAGlC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAA,SAAI,GAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,EAAW,GAAe,EAAE,GAAW,EAAc,EAAE;IACxE,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAI,GAAG,CAAC,CAAC;IACnC,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,OAAO,UAAU,CAAC;KACrB;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,MAAM,OAAO,GAAG,CAAC,OAAsB,EAAE,EAAE;YACvC,IAAI,OAAO,CAAC,GAAG,KAAK,GAAG,EAAE;gBACrB,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;gBACjC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAI,OAAO,CAAC,GAAG,CAAC,CAAC;gBACtC,IAAI,KA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I,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;IACnE,CAAC;;AA9BL,sDA+BC;AA9B0B,0BAAI,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n FluidObject,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport {\n FluidDataStoreRuntime,\n FluidObjectHandle,\n ISharedObjectRegistry,\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 IFluidDataStoreContext,\n IFluidDataStoreFactory,\n NamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\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 const maybeValue = map.get<T>(key);\n if (maybeValue !== undefined) {\n return maybeValue;\n }\n\n return new Promise((resolve) => {\n const handler = (changed: IValueChanged) => {\n if (changed.key === key) {\n map.off(\"valueChanged\", handler);\n const value = map.get<T>(changed.key);\n if (value === undefined) {\n throw new Error(\"Unexpected valueChanged result\");\n }\n resolve(value);\n }\n };\n map.on(\"valueChanged\", handler);\n });\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {\n public static async load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean) {\n let root: ISharedMap;\n let consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n if (!existing) {\n root = SharedMap.create(runtime, \"root\");\n root.bindToContext();\n consensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n consensusRegisterCollection.bindToContext();\n root.set(schedulerId, consensusRegisterCollection.handle);\n } else {\n root = await runtime.getChannel(\"root\") as ISharedMap;\n const handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(root, schedulerId);\n assert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n consensusRegisterCollection = await handle.get();\n }\n const agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n agentScheduler.initialize();\n\n return agentScheduler;\n }\n\n public get IAgentScheduler() { return this; }\n public get IFluidLoadable() { return this; }\n\n private get clientId(): string {\n if (this.runtime.attachState === AttachState.Detached) {\n return UnattachedClientId;\n }\n const clientId = this.runtime.clientId;\n assert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n return clientId;\n }\n\n // Set of tasks registered by this client.\n // Has no relationship with lists below.\n // The only requirement here - a task can be registered by a client only once.\n // Other clients can pick these tasks.\n private readonly registeredTasks = new Set<string>();\n\n // List of all tasks client is capable of running (essentially expressed desire to run)\n // Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n // This is a strict superset of tasks running in the client.\n private readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n // Set of registered tasks client is currently running.\n // It's subset of this.locallyRunnableTasks\n private runningTasks = new Set<string>();\n\n private readonly _handle: IFluidHandle<this>;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly context: IFluidDataStoreContext,\n private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n ) {\n super();\n this._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n }\n\n public get handle() {\n return this._handle;\n }\n\n public async register(...taskUrls: string[]): Promise<void> {\n for (const taskUrl of taskUrls) {\n if (this.registeredTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} is already registered`);\n }\n }\n const unregisteredTasks: string[] = [];\n for (const taskUrl of taskUrls) {\n this.registeredTasks.add(taskUrl);\n // Only register for a new task.\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient === undefined) {\n unregisteredTasks.push(taskUrl);\n }\n }\n return this.registerCore(unregisteredTasks);\n }\n\n public async pick(taskId: string, worker: () => Promise<void>): Promise<void> {\n if (this.locallyRunnableTasks.has(taskId)) {\n throw new Error(`${taskId} is already attempted`);\n }\n this.locallyRunnableTasks.set(taskId, worker);\n\n // We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n // either perform this check proactively and call conditionally, or catch the error (in which case\n // they can know they will not get the task).\n assert(this.context.deltaManager.clientDetails.capabilities.interactive,\n 0x118 /* \"Bad client interactive check\" */);\n\n // Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n if (this.isActive()) {\n const currentClient = this.getTaskClientId(taskId);\n if (currentClient === undefined || currentClient === null) {\n await this.writeCore(taskId, this.clientId);\n }\n }\n }\n\n public async release(...taskUrls: string[]): Promise<void> {\n const active = this.isActive();\n for (const taskUrl of taskUrls) {\n if (!this.locallyRunnableTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} was never registered`);\n }\n // Note - the assumption is - we are connected.\n // If not - all tasks should have been dropped already on disconnect / attachment\n assert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n if (this.getTaskClientId(taskUrl) !== this.clientId) {\n throw new Error(`${taskUrl} was never picked`);\n }\n }\n return this.releaseCore([...taskUrls]);\n }\n\n public pickedTasks(): string[] {\n return Array.from(this.runningTasks.values());\n }\n\n private async registerCore(taskUrls: string[]): Promise<void> {\n if (taskUrls.length > 0) {\n const registersP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n registersP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(registersP);\n\n // The registers should have up to date results now. Check the status.\n for (const taskUrl of taskUrls) {\n const taskStatus = this.getTaskClientId(taskUrl);\n\n // Task should be either registered (null) or picked up.\n assert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n }\n }\n }\n\n private async releaseCore(taskUrls: string[]) {\n if (taskUrls.length > 0) {\n const releasesP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n // Remove from local map so that it can be picked later.\n this.locallyRunnableTasks.delete(taskUrl);\n releasesP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(releasesP);\n }\n }\n\n private async clearTasks(taskUrls: string[]) {\n assert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n const clearP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n clearP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(clearP);\n }\n\n private getTaskClientId(url: string): string | null | undefined {\n return this.consensusRegisterCollection.read(url);\n }\n\n private async writeCore(key: string, clientId: string | null): Promise<void> {\n await this.consensusRegisterCollection.write(key, clientId);\n }\n\n private initialize() {\n const quorum = this.runtime.getQuorum();\n // A client left the quorum. Iterate and clear tasks held by that client.\n // Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n // Probably okay for now to have every client try to do this.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n quorum.on(\"removeMember\", async (clientId: string) => {\n assert(this.runtime.objectsRoutingContext.isAttached, 0x11c /* \"Detached object routing context\" */);\n // Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n if (this.isActive()) {\n const tasks: Promise<any>[] = [];\n const leftTasks: string[] = [];\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n if (this.getTaskClientId(taskUrl) === clientId) {\n if (this.locallyRunnableTasks.has(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n } else {\n leftTasks.push(taskUrl);\n }\n }\n }\n tasks.push(this.clearTasks(leftTasks));\n await Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n });\n }\n });\n\n // Listeners for new/released tasks. All clients will try to grab at the same time.\n // May be we want a randomized timer (Something like raft) to reduce chattiness?\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.consensusRegisterCollection.on(\"atomicChanged\", async (key: string, currentClient: string | null) => {\n // Check if this client was chosen.\n if (this.isActive() && currentClient === this.clientId) {\n this.onNewTaskAssigned(key);\n } else {\n await this.onTaskReassigned(key, currentClient);\n }\n });\n\n if (this.isActive()) {\n this.initializeCore();\n }\n\n this.runtime.on(\"connected\", () => {\n if (this.isActive()) {\n this.initializeCore();\n }\n });\n\n if (this.runtime.attachState === AttachState.Detached) {\n this.runtime.waitAttached().then(() => {\n this.clearRunningTasks();\n }).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n });\n }\n\n this.runtime.on(\"disconnected\", () => {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.clearRunningTasks();\n }\n });\n }\n\n private onNewTaskAssigned(key: string) {\n assert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n this.runningTasks.add(key);\n const worker = this.locallyRunnableTasks.get(key);\n if (worker === undefined) {\n this.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n } else {\n this.emit(\"picked\", key);\n worker().catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n });\n }\n }\n\n private async onTaskReassigned(key: string, currentClient: string | null) {\n if (this.runningTasks.has(key)) {\n this.runningTasks.delete(key);\n this.emit(\"released\", key);\n }\n assert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n /* eslint-disable @typescript-eslint/brace-style */\n if (this.isActive()) {\n // attempt to pick up task if we are connected.\n // If not, initializeCore() will do it when connected\n if (currentClient === null) {\n if (this.locallyRunnableTasks.has(key)) {\n await this.writeCore(key, this.clientId);\n }\n }\n // Check if the op came from dropped client\n // This could happen when \"old\" ops are submitted on reconnection.\n // They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n else if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n await this.writeCore(key, null);\n }\n }\n /* eslint-enable @typescript-eslint/brace-style */\n }\n\n private isActive() {\n // Scheduler should be active in detached container.\n if (this.runtime.attachState === AttachState.Detached) {\n return true;\n }\n if (!this.runtime.connected) {\n return false;\n }\n\n // Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n // here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n return this.context.deltaManager.active;\n }\n\n private initializeCore() {\n // Nobody released the tasks held by last client in previous session.\n // Check to see if this client needs to do this.\n const clearCandidates: string[] = [];\n const tasks: Promise<any>[] = [];\n\n for (const [taskUrl] of this.locallyRunnableTasks) {\n if (!this.getTaskClientId(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n }\n }\n\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n clearCandidates.push(taskUrl);\n }\n }\n\n tasks.push(this.clearTasks(clearCandidates));\n\n Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_InitError\", error);\n });\n }\n\n private clearRunningTasks() {\n const tasks = this.runningTasks;\n this.runningTasks = new Set<string>();\n\n if (this.isActive()) {\n // Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n // If we are simply disconnected, then proper cleanup will be done on connection.\n this.initializeCore();\n }\n\n for (const task of tasks) {\n this.emit(\"lost\", task);\n }\n }\n\n private sendErrorEvent(eventName: string, error: any, key?: string) {\n this.runtime.logger.sendErrorEvent({ eventName, key }, error);\n }\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n constructor(\n dataStoreContext: IFluidDataStoreContext,\n sharedObjectRegistry: ISharedObjectRegistry,\n existing: boolean,\n ) {\n super(\n dataStoreContext,\n sharedObjectRegistry,\n existing,\n async () => AgentScheduler.load(this, dataStoreContext, existing));\n }\n public async request(request: IRequest) {\n const response = await super.request(request);\n if (response.status === 404) {\n if (request.url === \"\" || request.url === \"/\") {\n const agentScheduler = await this.entryPoint?.get();\n assert(agentScheduler !== undefined,\n 0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */);\n\n return { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n }\n }\n return response;\n }\n}\n\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n public static readonly type = \"_scheduler\";\n public readonly type = AgentSchedulerFactory.type;\n\n public get IFluidDataStoreFactory() { return this; }\n\n public static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n return [this.type, Promise.resolve(new AgentSchedulerFactory())];\n }\n\n public static async createChildInstance(parentContext: IFluidDataStoreContext): Promise<AgentScheduler> {\n const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n const entryPoint: FluidObject<IAgentScheduler> | undefined = await dataStore.entryPoint?.get();\n\n // AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n // while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n assert(entryPoint?.IAgentScheduler !== undefined,\n 0x467 /* The data store's entryPoint is not an AgentScheduler! */);\n return entryPoint as unknown as AgentScheduler;\n }\n\n public async instantiateDataStore(context: IFluidDataStoreContext, existing: boolean) {\n const mapFactory = SharedMap.getFactory();\n const consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n const dataTypes = new Map<string, IChannelFactory>();\n dataTypes.set(mapFactory.type, mapFactory);\n dataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n return new AgentSchedulerRuntime(context, dataTypes, existing);\n }\n}\n"]}
package/lib/agent.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
6
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
6
7
  export declare const IAgentScheduler: keyof IProvideAgentScheduler;
7
8
  export interface IProvideAgentScheduler {
8
9
  readonly IAgentScheduler: IAgentScheduler;
@@ -30,7 +31,7 @@ export interface IAgentSchedulerEvents extends IEvent {
30
31
  /**
31
32
  * Agent scheduler distributes a set of tasks/variables across connected clients.
32
33
  */
33
- export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents> {
34
+ export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents>, IFluidLoadable {
34
35
  /**
35
36
  * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants
36
37
  * a new agent to run but does not have the capability to run the agent inside the host.
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAE5E,eAAO,MAAM,eAAe,EAAE,MAAM,sBAA0C,CAAC;AAE/E,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC7C;AAED,MAAM,WAAW,qBAAsB,SAAQ,MAAM;IACjD;;;;;;;;;;;;;;;;OAgBG;IACH,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,OAAE;CAC/E;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,sBAAsB,EAAE,cAAc,CAAC,qBAAqB,CAAC;IAClG;;;;;;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,C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file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,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 } from \"@fluidframework/common-definitions\";\n\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\nexport interface IProvideAgentScheduler {\n readonly IAgentScheduler: IAgentScheduler;\n}\n\nexport interface IAgentSchedulerEvents extends IEvent {\n /**\n * Event when ownership of task changes\n * @param event - name of the event:\n *\n * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n * automatically, unless release() is called\n *\n * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n * re-acquire the task, unless pick() is called.\n *\n * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n * Task will be picked up again by some connected client (this client will try as well,\n * unless release() is called)\n *\n * @param listener - callback notified when change happened for particular key\n */\n (event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n */\nexport interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents> {\n /**\n * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n * a new agent to run but does not have the capability to run the agent inside the host.\n * Client can call pick() later if the capability changes.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n */\n register(...taskUrls: string[]): Promise<void>;\n\n /**\n * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n * Resolves when the tasks are assigned to one of the connected clients.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n *\n * @param worker - callback to run when task is picked up.\n */\n pick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n /**\n * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n *\n * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n * App can call pickedTasks() to get the picked list first.\n */\n release(...taskUrls: string[]): Promise<void>;\n\n /**\n * Returns a list of all tasks running on this client\n */\n pickedTasks(): string[];\n}\n"]}
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,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 } from \"@fluidframework/common-definitions\";\nimport { IFluidLoadable } from \"@fluidframework/core-interfaces\";\n\nexport const IAgentScheduler: keyof IProvideAgentScheduler = \"IAgentScheduler\";\n\nexport interface IProvideAgentScheduler {\n readonly IAgentScheduler: IAgentScheduler;\n}\n\nexport interface IAgentSchedulerEvents extends IEvent {\n /**\n * Event when ownership of task changes\n * @param event - name of the event:\n *\n * - \"picked\" - the task has been assigned to this client, in response to pick() being called\n * If client loses this task (due to disconnect), it will attempt to pick it again (on connection)\n * automatically, unless release() is called\n *\n * - \"released\" - the task was successfully released back to the pool. Client will not attempt to\n * re-acquire the task, unless pick() is called.\n *\n * - \"lost\" - task is lost due to disconnect or data store / container being attached.\n * Task will be picked up again by some connected client (this client will try as well,\n * unless release() is called)\n *\n * @param listener - callback notified when change happened for particular key\n */\n (event: \"picked\" | \"released\" | \"lost\", listener: (taskId: string) => void);\n}\n\n/**\n * Agent scheduler distributes a set of tasks/variables across connected clients.\n */\nexport interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents>, IFluidLoadable {\n /**\n * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants\n * a new agent to run but does not have the capability to run the agent inside the host.\n * Client can call pick() later if the capability changes.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n */\n register(...taskUrls: string[]): Promise<void>;\n\n /**\n * Attempts to pick a set of tasks. A client will only run the task if it's chosen based on consensus.\n * Resolves when the tasks are assigned to one of the connected clients.\n *\n * This method should only be called once per task. Duplicate calls will be rejected.\n *\n * @param worker - callback to run when task is picked up.\n */\n pick(taskId: string, worker: () => Promise<void>): Promise<void>;\n\n /**\n * Releases a set of tasks for other clients to grab. Resolves when the tasks are released.\n *\n * Only previously picked tasks are allowed. Releasing non picked tasks will get a rejection.\n * App can call pickedTasks() to get the picked list first.\n */\n release(...taskUrls: string[]): Promise<void>;\n\n /**\n * Returns a list of all tasks running on this client\n */\n pickedTasks(): string[];\n}\n"]}
package/lib/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 * from "./agent";
5
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent";
6
6
  export { AgentSchedulerFactory } from "./scheduler";
7
- export * from "./taskSubscription";
7
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription";
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,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc,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,SAAS,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
package/lib/index.js 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 * from "./agent";
5
+ export { IAgentScheduler } from "./agent";
6
6
  export { AgentSchedulerFactory } from "./scheduler";
7
- export * from "./taskSubscription";
7
+ export { TaskSubscription } from "./taskSubscription";
8
8
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc,oBAAoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./agent\";\nexport { AgentSchedulerFactory } from \"./scheduler\";\nexport * from \"./taskSubscription\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAiD,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAA2B,gBAAgB,EAAE,MAAM,oBAAoB,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\";\nexport { AgentSchedulerFactory } from \"./scheduler\";\nexport { ITaskSubscriptionEvents, TaskSubscription } from \"./taskSubscription\";\n"]}
@@ -3,13 +3,13 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { TypedEventEmitter } from "@fluidframework/common-utils";
6
- import { IFluidHandle, IFluidLoadable, IRequest } from "@fluidframework/core-interfaces";
6
+ import { IFluidHandle, IRequest } from "@fluidframework/core-interfaces";
7
7
  import { FluidDataStoreRuntime, ISharedObjectRegistry } 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
11
  import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
12
- export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler, IFluidLoadable {
12
+ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {
13
13
  private readonly runtime;
14
14
  private readonly context;
15
15
  private readonly consensusRegisterCollection;
@@ -41,7 +41,6 @@ export declare class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEve
41
41
  private sendErrorEvent;
42
42
  }
43
43
  declare class AgentSchedulerRuntime extends FluidDataStoreRuntime {
44
- private readonly agentSchedulerP;
45
44
  constructor(dataStoreContext: IFluidDataStoreContext, sharedObjectRegistry: ISharedObjectRegistry, existing: boolean);
46
45
  request(request: IRequest): Promise<import("@fluidframework/core-interfaces").IResponse>;
47
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACH,YAAY,EACZ,cAAc,EACd,QAAQ,EACX,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,qBAAqB,EAErB,qBAAqB,EACxB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uCAAuC,CAAC;AAChG,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EACnC,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA4BjE,qBAAa,cACT,SAAQ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Aa,qBAAsB,YAAW,sBAAsB;IAChE,gBAAuB,IAAI,gBAAgB;IAC3C,SAAgB,IAAI,gBAA8B;IAElD,IAAW,sBAAsB,SAAmB;IAEpD,WAAkB,aAAa,IAAI,gCAAgC,CAElE;WAEmB,mBAAmB,CAAC,aAAa,EAAE,sBAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;IAY1F,oBAAoB,CAAC,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,OAAO;CASvF"}
package/lib/scheduler.js CHANGED
@@ -7,7 +7,6 @@ import { FluidDataStoreRuntime, FluidObjectHandle, } from "@fluidframework/datas
7
7
  import { AttachState } from "@fluidframework/container-definitions";
8
8
  import { SharedMap } from "@fluidframework/map";
9
9
  import { ConsensusRegisterCollection } from "@fluidframework/register-collection";
10
- import { requestFluidObject } from "@fluidframework/runtime-utils";
11
10
  import { v4 as uuid } from "uuid";
12
11
  // Note: making sure this ID is unique and does not collide with storage provided clientID
13
12
  const UnattachedClientId = `${uuid()}_unattached`;
@@ -326,14 +325,15 @@ export class AgentScheduler extends TypedEventEmitter {
326
325
  }
327
326
  class AgentSchedulerRuntime extends FluidDataStoreRuntime {
328
327
  constructor(dataStoreContext, sharedObjectRegistry, existing) {
329
- super(dataStoreContext, sharedObjectRegistry, existing);
330
- this.agentSchedulerP = AgentScheduler.load(this, dataStoreContext, existing);
328
+ super(dataStoreContext, sharedObjectRegistry, existing, async () => AgentScheduler.load(this, dataStoreContext, existing));
331
329
  }
332
330
  async request(request) {
331
+ var _a;
333
332
  const response = await super.request(request);
334
333
  if (response.status === 404) {
335
334
  if (request.url === "" || request.url === "/") {
336
- const agentScheduler = await this.agentSchedulerP;
335
+ const agentScheduler = await ((_a = this.entryPoint) === null || _a === void 0 ? void 0 : _a.get());
336
+ assert(agentScheduler !== undefined, 0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */);
337
337
  return { status: 200, mimeType: "fluid/object", value: agentScheduler };
338
338
  }
339
339
  }
@@ -349,9 +349,14 @@ export class AgentSchedulerFactory {
349
349
  return [this.type, Promise.resolve(new AgentSchedulerFactory())];
350
350
  }
351
351
  static async createChildInstance(parentContext) {
352
+ var _a;
352
353
  const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];
353
- const router = await parentContext.containerRuntime.createDataStore(packagePath);
354
- return requestFluidObject(router, "/");
354
+ const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);
355
+ const entryPoint = await ((_a = dataStore.entryPoint) === null || _a === void 0 ? void 0 : _a.get());
356
+ // AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check
357
+ // while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.
358
+ assert((entryPoint === null || entryPoint === void 0 ? void 0 : entryPoint.IAgentScheduler) !== undefined, 0x467 /* The data store's entryPoint is not an AgentScheduler! */);
359
+ return entryPoint;
355
360
  }
356
361
  async instantiateDataStore(context, existing) {
357
362
  const mapFactory = SharedMap.getFactory();
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMzE,OAAO,EACH,qBAAqB,EACrB,iBAAiB,GAEpB,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,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAGlC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,GAAG,IAAI,EAAE,aAAa,CAAC;AAElD,MAAM,OAAO,GAAG,KAAK,EAAW,GAAe,EAAE,GAAW,EAAc,E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,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;IACnE,CAAC;;AAvBsB,0BAAI,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n IFluidHandle,\n IFluidLoadable,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport {\n FluidDataStoreRuntime,\n FluidObjectHandle,\n ISharedObjectRegistry,\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 IFluidDataStoreContext,\n IFluidDataStoreFactory,\n NamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport { v4 as uuid } from \"uuid\";\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 const maybeValue = map.get<T>(key);\n if (maybeValue !== undefined) {\n return maybeValue;\n }\n\n return new Promise((resolve) => {\n const handler = (changed: IValueChanged) => {\n if (changed.key === key) {\n map.off(\"valueChanged\", handler);\n const value = map.get<T>(changed.key);\n if (value === undefined) {\n throw new Error(\"Unexpected valueChanged result\");\n }\n resolve(value);\n }\n };\n map.on(\"valueChanged\", handler);\n });\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler\n extends TypedEventEmitter<IAgentSchedulerEvents>\n implements IAgentScheduler, IFluidLoadable\n{ // eslint-disable-line @typescript-eslint/brace-style\n public static async load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean) {\n let root: ISharedMap;\n let consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n if (!existing) {\n root = SharedMap.create(runtime, \"root\");\n root.bindToContext();\n consensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n consensusRegisterCollection.bindToContext();\n root.set(schedulerId, consensusRegisterCollection.handle);\n } else {\n root = await runtime.getChannel(\"root\") as ISharedMap;\n const handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(root, schedulerId);\n assert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n consensusRegisterCollection = await handle.get();\n }\n const agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n agentScheduler.initialize();\n\n return agentScheduler;\n }\n\n public get IAgentScheduler() { return this; }\n public get IFluidLoadable() { return this; }\n\n private get clientId(): string {\n if (this.runtime.attachState === AttachState.Detached) {\n return UnattachedClientId;\n }\n const clientId = this.runtime.clientId;\n assert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n return clientId;\n }\n\n // Set of tasks registered by this client.\n // Has no relationship with lists below.\n // The only requirement here - a task can be registered by a client only once.\n // Other clients can pick these tasks.\n private readonly registeredTasks = new Set<string>();\n\n // List of all tasks client is capable of running (essentially expressed desire to run)\n // Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n // This is a strict superset of tasks running in the client.\n private readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n // Set of registered tasks client is currently running.\n // It's subset of this.locallyRunnableTasks\n private runningTasks = new Set<string>();\n\n private readonly _handle: IFluidHandle<this>;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly context: IFluidDataStoreContext,\n private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n ) {\n super();\n this._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n }\n\n public get handle() {\n return this._handle;\n }\n\n public async register(...taskUrls: string[]): Promise<void> {\n for (const taskUrl of taskUrls) {\n if (this.registeredTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} is already registered`);\n }\n }\n const unregisteredTasks: string[] = [];\n for (const taskUrl of taskUrls) {\n this.registeredTasks.add(taskUrl);\n // Only register for a new task.\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient === undefined) {\n unregisteredTasks.push(taskUrl);\n }\n }\n return this.registerCore(unregisteredTasks);\n }\n\n public async pick(taskId: string, worker: () => Promise<void>): Promise<void> {\n if (this.locallyRunnableTasks.has(taskId)) {\n throw new Error(`${taskId} is already attempted`);\n }\n this.locallyRunnableTasks.set(taskId, worker);\n\n // We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n // either perform this check proactively and call conditionally, or catch the error (in which case\n // they can know they will not get the task).\n assert(this.context.deltaManager.clientDetails.capabilities.interactive,\n 0x118 /* \"Bad client interactive check\" */);\n\n // Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n if (this.isActive()) {\n const currentClient = this.getTaskClientId(taskId);\n if (currentClient === undefined || currentClient === null) {\n await this.writeCore(taskId, this.clientId);\n }\n }\n }\n\n public async release(...taskUrls: string[]): Promise<void> {\n const active = this.isActive();\n for (const taskUrl of taskUrls) {\n if (!this.locallyRunnableTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} was never registered`);\n }\n // Note - the assumption is - we are connected.\n // If not - all tasks should have been dropped already on disconnect / attachment\n assert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n if (this.getTaskClientId(taskUrl) !== this.clientId) {\n throw new Error(`${taskUrl} was never picked`);\n }\n }\n return this.releaseCore([...taskUrls]);\n }\n\n public pickedTasks(): string[] {\n return Array.from(this.runningTasks.values());\n }\n\n private async registerCore(taskUrls: string[]): Promise<void> {\n if (taskUrls.length > 0) {\n const registersP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n registersP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(registersP);\n\n // The registers should have up to date results now. Check the status.\n for (const taskUrl of taskUrls) {\n const taskStatus = this.getTaskClientId(taskUrl);\n\n // Task should be either registered (null) or picked up.\n assert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n }\n }\n }\n\n private async releaseCore(taskUrls: string[]) {\n if (taskUrls.length > 0) {\n const releasesP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n // Remove from local map so that it can be picked later.\n this.locallyRunnableTasks.delete(taskUrl);\n releasesP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(releasesP);\n }\n }\n\n private async clearTasks(taskUrls: string[]) {\n assert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n const clearP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n clearP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(clearP);\n }\n\n private getTaskClientId(url: string): string | null | undefined {\n return this.consensusRegisterCollection.read(url);\n }\n\n private async writeCore(key: string, clientId: string | null): Promise<void> {\n await this.consensusRegisterCollection.write(key, clientId);\n }\n\n private initialize() {\n const quorum = this.runtime.getQuorum();\n // A client left the quorum. Iterate and clear tasks held by that client.\n // Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n // Probably okay for now to have every client try to do this.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n quorum.on(\"removeMember\", async (clientId: string) => {\n assert(this.runtime.objectsRoutingContext.isAttached, 0x11c /* \"Detached object routing context\" */);\n // Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n if (this.isActive()) {\n const tasks: Promise<any>[] = [];\n const leftTasks: string[] = [];\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n if (this.getTaskClientId(taskUrl) === clientId) {\n if (this.locallyRunnableTasks.has(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n } else {\n leftTasks.push(taskUrl);\n }\n }\n }\n tasks.push(this.clearTasks(leftTasks));\n await Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n });\n }\n });\n\n // Listeners for new/released tasks. All clients will try to grab at the same time.\n // May be we want a randomized timer (Something like raft) to reduce chattiness?\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.consensusRegisterCollection.on(\"atomicChanged\", async (key: string, currentClient: string | null) => {\n // Check if this client was chosen.\n if (this.isActive() && currentClient === this.clientId) {\n this.onNewTaskAssigned(key);\n } else {\n await this.onTaskReassigned(key, currentClient);\n }\n });\n\n if (this.isActive()) {\n this.initializeCore();\n }\n\n this.runtime.on(\"connected\", () => {\n if (this.isActive()) {\n this.initializeCore();\n }\n });\n\n if (this.runtime.attachState === AttachState.Detached) {\n this.runtime.waitAttached().then(() => {\n this.clearRunningTasks();\n }).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n });\n }\n\n this.runtime.on(\"disconnected\", () => {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.clearRunningTasks();\n }\n });\n }\n\n private onNewTaskAssigned(key: string) {\n assert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n this.runningTasks.add(key);\n const worker = this.locallyRunnableTasks.get(key);\n if (worker === undefined) {\n this.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n } else {\n this.emit(\"picked\", key);\n worker().catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n });\n }\n }\n\n private async onTaskReassigned(key: string, currentClient: string | null) {\n if (this.runningTasks.has(key)) {\n this.runningTasks.delete(key);\n this.emit(\"released\", key);\n }\n assert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n /* eslint-disable @typescript-eslint/brace-style */\n if (this.isActive()) {\n // attempt to pick up task if we are connected.\n // If not, initializeCore() will do it when connected\n if (currentClient === null) {\n if (this.locallyRunnableTasks.has(key)) {\n await this.writeCore(key, this.clientId);\n }\n }\n // Check if the op came from dropped client\n // This could happen when \"old\" ops are submitted on reconnection.\n // They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n else if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n await this.writeCore(key, null);\n }\n }\n /* eslint-enable @typescript-eslint/brace-style */\n }\n\n private isActive() {\n // Scheduler should be active in detached container.\n if (this.runtime.attachState === AttachState.Detached) {\n return true;\n }\n if (!this.runtime.connected) {\n return false;\n }\n\n // Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n // here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n return this.context.deltaManager.active;\n }\n\n private initializeCore() {\n // Nobody released the tasks held by last client in previous session.\n // Check to see if this client needs to do this.\n const clearCandidates: string[] = [];\n const tasks: Promise<any>[] = [];\n\n for (const [taskUrl] of this.locallyRunnableTasks) {\n if (!this.getTaskClientId(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n }\n }\n\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n clearCandidates.push(taskUrl);\n }\n }\n\n tasks.push(this.clearTasks(clearCandidates));\n\n Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_InitError\", error);\n });\n }\n\n private clearRunningTasks() {\n const tasks = this.runningTasks;\n this.runningTasks = new Set<string>();\n\n if (this.isActive()) {\n // Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n // If we are simply disconnected, then proper cleanup will be done on connection.\n this.initializeCore();\n }\n\n for (const task of tasks) {\n this.emit(\"lost\", task);\n }\n }\n\n private sendErrorEvent(eventName: string, error: any, key?: string) {\n this.runtime.logger.sendErrorEvent({ eventName, key }, error);\n }\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n private readonly agentSchedulerP: Promise<AgentScheduler>;\n constructor(\n dataStoreContext: IFluidDataStoreContext,\n sharedObjectRegistry: ISharedObjectRegistry,\n existing: boolean,\n ) {\n super(dataStoreContext, sharedObjectRegistry, existing);\n this.agentSchedulerP = AgentScheduler.load(this, dataStoreContext, existing);\n }\n public async request(request: IRequest) {\n const response = await super.request(request);\n if (response.status === 404) {\n if (request.url === \"\" || request.url === \"/\") {\n const agentScheduler = await this.agentSchedulerP;\n return { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n }\n }\n return response;\n }\n}\n\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n public static readonly type = \"_scheduler\";\n public readonly type = AgentSchedulerFactory.type;\n\n public get IFluidDataStoreFactory() { return this; }\n\n public static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n return [this.type, Promise.resolve(new AgentSchedulerFactory())];\n }\n\n public static async createChildInstance(parentContext: IFluidDataStoreContext): Promise<AgentScheduler> {\n const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n const router = await parentContext.containerRuntime.createDataStore(packagePath);\n return requestFluidObject<AgentScheduler>(router, \"/\");\n }\n\n public async instantiateDataStore(context: IFluidDataStoreContext, existing: boolean) {\n const mapFactory = SharedMap.getFactory();\n const consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n const dataTypes = new Map<string, IChannelFactory>();\n dataTypes.set(mapFactory.type, mapFactory);\n dataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n return new AgentSchedulerRuntime(context, dataTypes, existing);\n }\n}\n"]}
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMzE,OAAO,EACH,qBAAqB,EACrB,iBAAiB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAA6B,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AC,CAAC;QAC/E,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,UAAU,GAA6C,MAAM,CAAA,MAAA,SAAS,CAAC,UAAU,0CAAE,GAAG,EAAE,CAAA,CAAC;QAE/F,8GAA8G;QAC9G,6FAA6F;QAC7F,MAAM,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,eAAe,MAAK,SAAS,EAC5C,KAAK,CAAC,2DAA2D,CAAC,CAAC;QACvE,OAAO,UAAuC,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,OAA+B,EAAE,QAAiB;QAChF,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,kCAAkC,GAAG,2BAA2B,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;IACnE,CAAC;;AA7BsB,0BAAI,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n FluidObject,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport {\n FluidDataStoreRuntime,\n FluidObjectHandle,\n ISharedObjectRegistry,\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 IFluidDataStoreContext,\n IFluidDataStoreFactory,\n NamedFluidDataStoreRegistryEntry,\n} from \"@fluidframework/runtime-definitions\";\nimport { v4 as uuid } from \"uuid\";\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 const maybeValue = map.get<T>(key);\n if (maybeValue !== undefined) {\n return maybeValue;\n }\n\n return new Promise((resolve) => {\n const handler = (changed: IValueChanged) => {\n if (changed.key === key) {\n map.off(\"valueChanged\", handler);\n const value = map.get<T>(changed.key);\n if (value === undefined) {\n throw new Error(\"Unexpected valueChanged result\");\n }\n resolve(value);\n }\n };\n map.on(\"valueChanged\", handler);\n });\n};\n\nconst schedulerId = \"scheduler\";\n\nexport class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {\n public static async load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean) {\n let root: ISharedMap;\n let consensusRegisterCollection: ConsensusRegisterCollection<string | null>;\n if (!existing) {\n root = SharedMap.create(runtime, \"root\");\n root.bindToContext();\n consensusRegisterCollection = ConsensusRegisterCollection.create(runtime);\n consensusRegisterCollection.bindToContext();\n root.set(schedulerId, consensusRegisterCollection.handle);\n } else {\n root = await runtime.getChannel(\"root\") as ISharedMap;\n const handle = await mapWait<IFluidHandle<ConsensusRegisterCollection<string | null>>>(root, schedulerId);\n assert(handle !== undefined, 0x116 /* \"Missing handle on scheduler load\" */);\n consensusRegisterCollection = await handle.get();\n }\n const agentScheduler = new AgentScheduler(runtime, context, consensusRegisterCollection);\n agentScheduler.initialize();\n\n return agentScheduler;\n }\n\n public get IAgentScheduler() { return this; }\n public get IFluidLoadable() { return this; }\n\n private get clientId(): string {\n if (this.runtime.attachState === AttachState.Detached) {\n return UnattachedClientId;\n }\n const clientId = this.runtime.clientId;\n assert(!!clientId, 0x117 /* \"Trying to get missing clientId!\" */);\n return clientId;\n }\n\n // Set of tasks registered by this client.\n // Has no relationship with lists below.\n // The only requirement here - a task can be registered by a client only once.\n // Other clients can pick these tasks.\n private readonly registeredTasks = new Set<string>();\n\n // List of all tasks client is capable of running (essentially expressed desire to run)\n // Client will proactively attempt to pick them up these tasks if they are not assigned to other clients.\n // This is a strict superset of tasks running in the client.\n private readonly locallyRunnableTasks = new Map<string, () => Promise<void>>();\n\n // Set of registered tasks client is currently running.\n // It's subset of this.locallyRunnableTasks\n private runningTasks = new Set<string>();\n\n private readonly _handle: IFluidHandle<this>;\n\n constructor(\n private readonly runtime: IFluidDataStoreRuntime,\n private readonly context: IFluidDataStoreContext,\n private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,\n ) {\n super();\n this._handle = new FluidObjectHandle(this, \"\", this.runtime.objectsRoutingContext);\n }\n\n public get handle() {\n return this._handle;\n }\n\n public async register(...taskUrls: string[]): Promise<void> {\n for (const taskUrl of taskUrls) {\n if (this.registeredTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} is already registered`);\n }\n }\n const unregisteredTasks: string[] = [];\n for (const taskUrl of taskUrls) {\n this.registeredTasks.add(taskUrl);\n // Only register for a new task.\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient === undefined) {\n unregisteredTasks.push(taskUrl);\n }\n }\n return this.registerCore(unregisteredTasks);\n }\n\n public async pick(taskId: string, worker: () => Promise<void>): Promise<void> {\n if (this.locallyRunnableTasks.has(taskId)) {\n throw new Error(`${taskId} is already attempted`);\n }\n this.locallyRunnableTasks.set(taskId, worker);\n\n // We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can\n // either perform this check proactively and call conditionally, or catch the error (in which case\n // they can know they will not get the task).\n assert(this.context.deltaManager.clientDetails.capabilities.interactive,\n 0x118 /* \"Bad client interactive check\" */);\n\n // Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).\n if (this.isActive()) {\n const currentClient = this.getTaskClientId(taskId);\n if (currentClient === undefined || currentClient === null) {\n await this.writeCore(taskId, this.clientId);\n }\n }\n }\n\n public async release(...taskUrls: string[]): Promise<void> {\n const active = this.isActive();\n for (const taskUrl of taskUrls) {\n if (!this.locallyRunnableTasks.has(taskUrl)) {\n throw new Error(`${taskUrl} was never registered`);\n }\n // Note - the assumption is - we are connected.\n // If not - all tasks should have been dropped already on disconnect / attachment\n assert(active, 0x119 /* \"This agent became inactive while releasing\" */);\n if (this.getTaskClientId(taskUrl) !== this.clientId) {\n throw new Error(`${taskUrl} was never picked`);\n }\n }\n return this.releaseCore([...taskUrls]);\n }\n\n public pickedTasks(): string[] {\n return Array.from(this.runningTasks.values());\n }\n\n private async registerCore(taskUrls: string[]): Promise<void> {\n if (taskUrls.length > 0) {\n const registersP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n registersP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(registersP);\n\n // The registers should have up to date results now. Check the status.\n for (const taskUrl of taskUrls) {\n const taskStatus = this.getTaskClientId(taskUrl);\n\n // Task should be either registered (null) or picked up.\n assert(taskStatus !== undefined, 0x11a /* `Unsuccessful registration` */);\n }\n }\n }\n\n private async releaseCore(taskUrls: string[]) {\n if (taskUrls.length > 0) {\n const releasesP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n // Remove from local map so that it can be picked later.\n this.locallyRunnableTasks.delete(taskUrl);\n releasesP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(releasesP);\n }\n }\n\n private async clearTasks(taskUrls: string[]) {\n assert(this.isActive(), 0x11b /* \"Trying to clear tasks on inactive agent\" */);\n const clearP: Promise<void>[] = [];\n for (const taskUrl of taskUrls) {\n clearP.push(this.writeCore(taskUrl, null));\n }\n await Promise.all(clearP);\n }\n\n private getTaskClientId(url: string): string | null | undefined {\n return this.consensusRegisterCollection.read(url);\n }\n\n private async writeCore(key: string, clientId: string | null): Promise<void> {\n await this.consensusRegisterCollection.write(key, clientId);\n }\n\n private initialize() {\n const quorum = this.runtime.getQuorum();\n // A client left the quorum. Iterate and clear tasks held by that client.\n // Ideally a leader should do this cleanup. But it's complicated when a leader itself leaves.\n // Probably okay for now to have every client try to do this.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n quorum.on(\"removeMember\", async (clientId: string) => {\n assert(this.runtime.objectsRoutingContext.isAttached, 0x11c /* \"Detached object routing context\" */);\n // Cleanup only if connected. If not, cleanup will happen in initializeCore() that runs on connection.\n if (this.isActive()) {\n const tasks: Promise<any>[] = [];\n const leftTasks: string[] = [];\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n if (this.getTaskClientId(taskUrl) === clientId) {\n if (this.locallyRunnableTasks.has(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n } else {\n leftTasks.push(taskUrl);\n }\n }\n }\n tasks.push(this.clearTasks(leftTasks));\n await Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_RemoveMemberError\", error);\n });\n }\n });\n\n // Listeners for new/released tasks. All clients will try to grab at the same time.\n // May be we want a randomized timer (Something like raft) to reduce chattiness?\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.consensusRegisterCollection.on(\"atomicChanged\", async (key: string, currentClient: string | null) => {\n // Check if this client was chosen.\n if (this.isActive() && currentClient === this.clientId) {\n this.onNewTaskAssigned(key);\n } else {\n await this.onTaskReassigned(key, currentClient);\n }\n });\n\n if (this.isActive()) {\n this.initializeCore();\n }\n\n this.runtime.on(\"connected\", () => {\n if (this.isActive()) {\n this.initializeCore();\n }\n });\n\n if (this.runtime.attachState === AttachState.Detached) {\n this.runtime.waitAttached().then(() => {\n this.clearRunningTasks();\n }).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_clearRunningTasks\", error);\n });\n }\n\n this.runtime.on(\"disconnected\", () => {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.clearRunningTasks();\n }\n });\n }\n\n private onNewTaskAssigned(key: string) {\n assert(!this.runningTasks.has(key), 0x11d /* \"task is already running\" */);\n this.runningTasks.add(key);\n const worker = this.locallyRunnableTasks.get(key);\n if (worker === undefined) {\n this.sendErrorEvent(\"AgentScheduler_UnwantedChange\", undefined, key);\n } else {\n this.emit(\"picked\", key);\n worker().catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_FailedWork\", error, key);\n });\n }\n }\n\n private async onTaskReassigned(key: string, currentClient: string | null) {\n if (this.runningTasks.has(key)) {\n this.runningTasks.delete(key);\n this.emit(\"released\", key);\n }\n assert(currentClient !== undefined, 0x11e /* \"client is undefined\" */);\n /* eslint-disable @typescript-eslint/brace-style */\n if (this.isActive()) {\n // attempt to pick up task if we are connected.\n // If not, initializeCore() will do it when connected\n if (currentClient === null) {\n if (this.locallyRunnableTasks.has(key)) {\n await this.writeCore(key, this.clientId);\n }\n }\n // Check if the op came from dropped client\n // This could happen when \"old\" ops are submitted on reconnection.\n // They carry \"old\" ref seq number, but if write is not contested, it will get accepted\n else if (this.runtime.getQuorum().getMember(currentClient) === undefined) {\n await this.writeCore(key, null);\n }\n }\n /* eslint-enable @typescript-eslint/brace-style */\n }\n\n private isActive() {\n // Scheduler should be active in detached container.\n if (this.runtime.attachState === AttachState.Detached) {\n return true;\n }\n if (!this.runtime.connected) {\n return false;\n }\n\n // Note: we are not checking for this.context.deltaManager.clientDetails.capabilities.interactive\n // here. Instead we assert in pick() if a non-interactive client tries to pick.\n\n return this.context.deltaManager.active;\n }\n\n private initializeCore() {\n // Nobody released the tasks held by last client in previous session.\n // Check to see if this client needs to do this.\n const clearCandidates: string[] = [];\n const tasks: Promise<any>[] = [];\n\n for (const [taskUrl] of this.locallyRunnableTasks) {\n if (!this.getTaskClientId(taskUrl)) {\n tasks.push(this.writeCore(taskUrl, this.clientId));\n }\n }\n\n for (const taskUrl of this.consensusRegisterCollection.keys()) {\n const currentClient = this.getTaskClientId(taskUrl);\n if (currentClient && this.runtime.getQuorum().getMember(currentClient) === undefined) {\n clearCandidates.push(taskUrl);\n }\n }\n\n tasks.push(this.clearTasks(clearCandidates));\n\n Promise.all(tasks).catch((error) => {\n this.sendErrorEvent(\"AgentScheduler_InitError\", error);\n });\n }\n\n private clearRunningTasks() {\n const tasks = this.runningTasks;\n this.runningTasks = new Set<string>();\n\n if (this.isActive()) {\n // Clear all tasks with UnattachedClientId (if was unattached) and reapply for tasks with new clientId\n // If we are simply disconnected, then proper cleanup will be done on connection.\n this.initializeCore();\n }\n\n for (const task of tasks) {\n this.emit(\"lost\", task);\n }\n }\n\n private sendErrorEvent(eventName: string, error: any, key?: string) {\n this.runtime.logger.sendErrorEvent({ eventName, key }, error);\n }\n}\n\nclass AgentSchedulerRuntime extends FluidDataStoreRuntime {\n constructor(\n dataStoreContext: IFluidDataStoreContext,\n sharedObjectRegistry: ISharedObjectRegistry,\n existing: boolean,\n ) {\n super(\n dataStoreContext,\n sharedObjectRegistry,\n existing,\n async () => AgentScheduler.load(this, dataStoreContext, existing));\n }\n public async request(request: IRequest) {\n const response = await super.request(request);\n if (response.status === 404) {\n if (request.url === \"\" || request.url === \"/\") {\n const agentScheduler = await this.entryPoint?.get();\n assert(agentScheduler !== undefined,\n 0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */);\n\n return { status: 200, mimeType: \"fluid/object\", value: agentScheduler };\n }\n }\n return response;\n }\n}\n\nexport class AgentSchedulerFactory implements IFluidDataStoreFactory {\n public static readonly type = \"_scheduler\";\n public readonly type = AgentSchedulerFactory.type;\n\n public get IFluidDataStoreFactory() { return this; }\n\n public static get registryEntry(): NamedFluidDataStoreRegistryEntry {\n return [this.type, Promise.resolve(new AgentSchedulerFactory())];\n }\n\n public static async createChildInstance(parentContext: IFluidDataStoreContext): Promise<AgentScheduler> {\n const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];\n const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);\n const entryPoint: FluidObject<IAgentScheduler> | undefined = await dataStore.entryPoint?.get();\n\n // AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check\n // while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.\n assert(entryPoint?.IAgentScheduler !== undefined,\n 0x467 /* The data store's entryPoint is not an AgentScheduler! */);\n return entryPoint as unknown as AgentScheduler;\n }\n\n public async instantiateDataStore(context: IFluidDataStoreContext, existing: boolean) {\n const mapFactory = SharedMap.getFactory();\n const consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();\n const dataTypes = new Map<string, IChannelFactory>();\n dataTypes.set(mapFactory.type, mapFactory);\n dataTypes.set(consensusRegisterCollectionFactory.type, consensusRegisterCollectionFactory);\n\n return new AgentSchedulerRuntime(context, dataTypes, existing);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/agent-scheduler",
3
- "version": "2.0.0-internal.2.0.2",
3
+ "version": "2.0.0-internal.2.1.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": {
@@ -16,7 +16,7 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "scripts": {
18
18
  "build": "concurrently npm:build:compile npm:lint",
19
- "build:compile": "npm run tsc && npm run build:test && npm run build:esnext",
19
+ "build:compile": "npm run tsc && npm run typetests:gen && npm run build:test && npm run build:esnext",
20
20
  "build:esnext": "tsc --project ./tsconfig.esnext.json",
21
21
  "build:full": "npm run build",
22
22
  "build:full:compile": "npm run build:compile",
@@ -28,8 +28,6 @@
28
28
  "lint": "npm run eslint",
29
29
  "lint:fix": "npm run eslint:fix",
30
30
  "tsc": "tsc",
31
- "tsfmt": "tsfmt --verify",
32
- "tsfmt:fix": "tsfmt --replace",
33
31
  "typetests:gen": "fluid-type-validator -g -d ."
34
32
  },
35
33
  "nyc": {
@@ -54,20 +52,22 @@
54
52
  "dependencies": {
55
53
  "@fluidframework/common-definitions": "^0.20.1",
56
54
  "@fluidframework/common-utils": "^1.0.0",
57
- "@fluidframework/container-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
58
- "@fluidframework/core-interfaces": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
59
- "@fluidframework/datastore": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
60
- "@fluidframework/datastore-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
61
- "@fluidframework/map": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
62
- "@fluidframework/register-collection": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
63
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
64
- "@fluidframework/runtime-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
55
+ "@fluidframework/container-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
56
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
57
+ "@fluidframework/datastore": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
58
+ "@fluidframework/datastore-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
59
+ "@fluidframework/map": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
60
+ "@fluidframework/register-collection": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
61
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
62
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
65
63
  "uuid": "^8.3.1"
66
64
  },
67
65
  "devDependencies": {
66
+ "@fluid-tools/build-cli": "^0.5.0",
68
67
  "@fluidframework/agent-scheduler-previous": "npm:@fluidframework/agent-scheduler@2.0.0-internal.2.0.0",
69
- "@fluidframework/build-common": "^1.0.0",
70
- "@fluidframework/eslint-config-fluid": "^1.0.0",
68
+ "@fluidframework/build-common": "^1.1.0",
69
+ "@fluidframework/build-tools": "^0.5.0",
70
+ "@fluidframework/eslint-config-fluid": "^1.1.0",
71
71
  "@rushstack/eslint-config": "^2.5.1",
72
72
  "@types/mocha": "^9.1.1",
73
73
  "@types/node": "^14.18.0",
@@ -76,8 +76,7 @@
76
76
  "mocha": "^10.0.0",
77
77
  "nyc": "^15.0.0",
78
78
  "rimraf": "^2.6.2",
79
- "typescript": "~4.5.5",
80
- "typescript-formatter": "7.1.0"
79
+ "typescript": "~4.5.5"
81
80
  },
82
81
  "fluid": {
83
82
  "browser": {
@@ -90,7 +89,14 @@
90
89
  }
91
90
  },
92
91
  "typeValidation": {
93
- "version": "2.0.0-internal.2.0.1",
94
- "broken": {}
92
+ "version": "2.0.0-internal.2.1.0",
93
+ "broken": {
94
+ "InterfaceDeclaration_IAgentScheduler": {
95
+ "forwardCompat": false
96
+ },
97
+ "InterfaceDeclaration_IProvideAgentScheduler": {
98
+ "forwardCompat": false
99
+ }
100
+ }
95
101
  }
96
102
  }
package/src/agent.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { IEvent, IEventProvider } from "@fluidframework/common-definitions";
7
+ import { IFluidLoadable } from "@fluidframework/core-interfaces";
7
8
 
8
9
  export const IAgentScheduler: keyof IProvideAgentScheduler = "IAgentScheduler";
9
10
 
@@ -35,7 +36,7 @@ export interface IAgentSchedulerEvents extends IEvent {
35
36
  /**
36
37
  * Agent scheduler distributes a set of tasks/variables across connected clients.
37
38
  */
38
- export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents> {
39
+ export interface IAgentScheduler extends IProvideAgentScheduler, IEventProvider<IAgentSchedulerEvents>, IFluidLoadable {
39
40
  /**
40
41
  * Registers a set of new tasks to distribute amongst connected clients. Only use this if a client wants
41
42
  * a new agent to run but does not have the capability to run the agent inside the host.
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- export * from "./agent";
6
+ export { IAgentScheduler, IAgentSchedulerEvents, IProvideAgentScheduler } from "./agent";
7
7
  export { AgentSchedulerFactory } from "./scheduler";
8
- export * from "./taskSubscription";
8
+ export { ITaskSubscriptionEvents, TaskSubscription } from "./taskSubscription";
package/src/scheduler.ts CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  import { assert, TypedEventEmitter } from "@fluidframework/common-utils";
7
7
  import {
8
+ FluidObject,
8
9
  IFluidHandle,
9
- IFluidLoadable,
10
10
  IRequest,
11
11
  } from "@fluidframework/core-interfaces";
12
12
  import {
@@ -23,7 +23,6 @@ import {
23
23
  IFluidDataStoreFactory,
24
24
  NamedFluidDataStoreRegistryEntry,
25
25
  } from "@fluidframework/runtime-definitions";
26
- import { requestFluidObject } from "@fluidframework/runtime-utils";
27
26
  import { v4 as uuid } from "uuid";
28
27
  import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
29
28
 
@@ -53,10 +52,7 @@ const mapWait = async <T = any>(map: ISharedMap, key: string): Promise<T> => {
53
52
 
54
53
  const schedulerId = "scheduler";
55
54
 
56
- export class AgentScheduler
57
- extends TypedEventEmitter<IAgentSchedulerEvents>
58
- implements IAgentScheduler, IFluidLoadable
59
- { // eslint-disable-line @typescript-eslint/brace-style
55
+ export class AgentScheduler extends TypedEventEmitter<IAgentSchedulerEvents> implements IAgentScheduler {
60
56
  public static async load(runtime: IFluidDataStoreRuntime, context: IFluidDataStoreContext, existing: boolean) {
61
57
  let root: ISharedMap;
62
58
  let consensusRegisterCollection: ConsensusRegisterCollection<string | null>;
@@ -392,20 +388,25 @@ export class AgentScheduler
392
388
  }
393
389
 
394
390
  class AgentSchedulerRuntime extends FluidDataStoreRuntime {
395
- private readonly agentSchedulerP: Promise<AgentScheduler>;
396
391
  constructor(
397
392
  dataStoreContext: IFluidDataStoreContext,
398
393
  sharedObjectRegistry: ISharedObjectRegistry,
399
394
  existing: boolean,
400
395
  ) {
401
- super(dataStoreContext, sharedObjectRegistry, existing);
402
- this.agentSchedulerP = AgentScheduler.load(this, dataStoreContext, existing);
396
+ super(
397
+ dataStoreContext,
398
+ sharedObjectRegistry,
399
+ existing,
400
+ async () => AgentScheduler.load(this, dataStoreContext, existing));
403
401
  }
404
402
  public async request(request: IRequest) {
405
403
  const response = await super.request(request);
406
404
  if (response.status === 404) {
407
405
  if (request.url === "" || request.url === "/") {
408
- const agentScheduler = await this.agentSchedulerP;
406
+ const agentScheduler = await this.entryPoint?.get();
407
+ assert(agentScheduler !== undefined,
408
+ 0x466 /* entryPoint for AgentSchedulerRuntime should have been initialized by now */);
409
+
409
410
  return { status: 200, mimeType: "fluid/object", value: agentScheduler };
410
411
  }
411
412
  }
@@ -425,8 +426,14 @@ export class AgentSchedulerFactory implements IFluidDataStoreFactory {
425
426
 
426
427
  public static async createChildInstance(parentContext: IFluidDataStoreContext): Promise<AgentScheduler> {
427
428
  const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];
428
- const router = await parentContext.containerRuntime.createDataStore(packagePath);
429
- return requestFluidObject<AgentScheduler>(router, "/");
429
+ const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);
430
+ const entryPoint: FluidObject<IAgentScheduler> | undefined = await dataStore.entryPoint?.get();
431
+
432
+ // AgentSchedulerRuntime always puts an AgentScheduler object in the data store's entryPoint, but double-check
433
+ // while we plumb entryPoints correctly everywhere, so we can be sure the cast below is fine.
434
+ assert(entryPoint?.IAgentScheduler !== undefined,
435
+ 0x467 /* The data store's entryPoint is not an AgentScheduler! */);
436
+ return entryPoint as unknown as AgentScheduler;
430
437
  }
431
438
 
432
439
  public async instantiateDataStore(context: IFluidDataStoreContext, existing: boolean) {