@fluidframework/agent-scheduler 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +4 -3
- package/api-extractor.json +4 -0
- package/dist/agent.d.ts +1 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/scheduler.d.ts +6 -11
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +28 -38
- package/dist/scheduler.js.map +1 -1
- package/dist/taskSubscription.d.ts +2 -2
- package/dist/taskSubscription.d.ts.map +1 -1
- package/dist/taskSubscription.js +2 -2
- package/dist/taskSubscription.js.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/agent.d.ts +1 -2
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js.map +1 -1
- package/lib/scheduler.d.ts +6 -11
- package/lib/scheduler.d.ts.map +1 -1
- package/lib/scheduler.js +18 -28
- package/lib/scheduler.js.map +1 -1
- package/lib/taskSubscription.d.ts +2 -2
- package/lib/taskSubscription.d.ts.map +1 -1
- package/lib/taskSubscription.js +1 -1
- package/lib/taskSubscription.js.map +1 -1
- package/package.json +25 -45
- package/src/agent.ts +1 -2
- package/src/scheduler.ts +20 -25
- package/src/taskSubscription.ts +2 -2
package/src/scheduler.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
|
+
import { assert } from "@fluidframework/core-utils";
|
|
7
8
|
import { FluidObject, IFluidHandle, IRequest } from "@fluidframework/core-interfaces";
|
|
8
|
-
import { UsageError } from "@fluidframework/container-utils";
|
|
9
9
|
import {
|
|
10
10
|
FluidDataStoreRuntime,
|
|
11
11
|
FluidObjectHandle,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
NamedFluidDataStoreRegistryEntry,
|
|
22
22
|
} from "@fluidframework/runtime-definitions";
|
|
23
23
|
import { v4 as uuid } from "uuid";
|
|
24
|
-
import {
|
|
24
|
+
import { tagCodeArtifacts, UsageError } from "@fluidframework/telemetry-utils";
|
|
25
25
|
import { IAgentScheduler, IAgentSchedulerEvents } from "./agent";
|
|
26
26
|
|
|
27
27
|
// Note: making sure this ID is unique and does not collide with storage provided clientID
|
|
@@ -121,6 +121,8 @@ export class AgentScheduler
|
|
|
121
121
|
private readonly consensusRegisterCollection: ConsensusRegisterCollection<string | null>,
|
|
122
122
|
) {
|
|
123
123
|
super();
|
|
124
|
+
// We are expecting this class to have many listeners, so we suppress noisy "MaxListenersExceededWarning" logging.
|
|
125
|
+
super.setMaxListeners(0);
|
|
124
126
|
this._handle = new FluidObjectHandle(this, "", this.runtime.objectsRoutingContext);
|
|
125
127
|
}
|
|
126
128
|
|
|
@@ -131,9 +133,7 @@ export class AgentScheduler
|
|
|
131
133
|
public async register(...taskUrls: string[]): Promise<void> {
|
|
132
134
|
for (const taskUrl of taskUrls) {
|
|
133
135
|
if (this.registeredTasks.has(taskUrl)) {
|
|
134
|
-
throw new UsageError(`Task is already registered`, {
|
|
135
|
-
taskUrl: { tag: TelemetryDataTag.CodeArtifact, value: taskUrl },
|
|
136
|
-
});
|
|
136
|
+
throw new UsageError(`Task is already registered`, tagCodeArtifacts({ taskUrl }));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
const unregisteredTasks: string[] = [];
|
|
@@ -148,13 +148,11 @@ export class AgentScheduler
|
|
|
148
148
|
return this.registerCore(unregisteredTasks);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
public async pick(
|
|
152
|
-
if (this.locallyRunnableTasks.has(
|
|
153
|
-
throw new UsageError(`Task is already attempted`, {
|
|
154
|
-
taskUrl: { tag: TelemetryDataTag.CodeArtifact, value: taskId },
|
|
155
|
-
});
|
|
151
|
+
public async pick(taskUrl: string, worker: () => Promise<void>): Promise<void> {
|
|
152
|
+
if (this.locallyRunnableTasks.has(taskUrl)) {
|
|
153
|
+
throw new UsageError(`Task is already attempted`, tagCodeArtifacts({ taskUrl }));
|
|
156
154
|
}
|
|
157
|
-
this.locallyRunnableTasks.set(
|
|
155
|
+
this.locallyRunnableTasks.set(taskUrl, worker);
|
|
158
156
|
|
|
159
157
|
// We have a policy to disallow non-interactive clients from taking tasks. Callers of pick() can
|
|
160
158
|
// either perform this check proactively and call conditionally, or catch the error (in which case
|
|
@@ -166,9 +164,9 @@ export class AgentScheduler
|
|
|
166
164
|
|
|
167
165
|
// Check the current status and express interest if it's a new one (undefined) or currently unpicked (null).
|
|
168
166
|
if (this.isActive()) {
|
|
169
|
-
const currentClient = this.getTaskClientId(
|
|
167
|
+
const currentClient = this.getTaskClientId(taskUrl);
|
|
170
168
|
if (currentClient === undefined || currentClient === null) {
|
|
171
|
-
await this.writeCore(
|
|
169
|
+
await this.writeCore(taskUrl, this.clientId);
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
}
|
|
@@ -177,9 +175,7 @@ export class AgentScheduler
|
|
|
177
175
|
const active = this.isActive();
|
|
178
176
|
for (const taskUrl of taskUrls) {
|
|
179
177
|
if (!this.locallyRunnableTasks.has(taskUrl)) {
|
|
180
|
-
throw new UsageError(`Task was never registered`, {
|
|
181
|
-
taskUrl: { tag: TelemetryDataTag.CodeArtifact, value: taskUrl },
|
|
182
|
-
});
|
|
178
|
+
throw new UsageError(`Task was never registered`, tagCodeArtifacts({ taskUrl }));
|
|
183
179
|
}
|
|
184
180
|
if (!this.runningTasks.has(taskUrl)) {
|
|
185
181
|
// If we got disconnected (and are attached), tasks that we WERE picked for at the time of disconnect
|
|
@@ -188,18 +184,14 @@ export class AgentScheduler
|
|
|
188
184
|
// ourselves clearing the task upon reconnect.
|
|
189
185
|
// This UsageError is to enforce that the caller should check AgentScheduler.pickedTasks before trying
|
|
190
186
|
// to release a task.
|
|
191
|
-
throw new UsageError(`Task is not currently picked`, {
|
|
192
|
-
taskUrl: { tag: TelemetryDataTag.CodeArtifact, value: taskUrl },
|
|
193
|
-
});
|
|
187
|
+
throw new UsageError(`Task is not currently picked`, tagCodeArtifacts({ taskUrl }));
|
|
194
188
|
}
|
|
195
189
|
// We may only release tasks that we KNOW we hold (detached state or connected and own the CRC). If we're
|
|
196
190
|
// attached+disconnected then we'll lose the task automatically, and so may not release manually (someone
|
|
197
191
|
// else might hold it by the time we reconnect)
|
|
198
192
|
assert(active, 0x119 /* "This agent became inactive while releasing" */);
|
|
199
193
|
if (this.getTaskClientId(taskUrl) !== this.clientId) {
|
|
200
|
-
throw new UsageError(`Task was never picked`, {
|
|
201
|
-
taskUrl: { tag: TelemetryDataTag.CodeArtifact, value: taskUrl },
|
|
202
|
-
});
|
|
194
|
+
throw new UsageError(`Task was never picked`, tagCodeArtifacts({ taskUrl }));
|
|
203
195
|
}
|
|
204
196
|
}
|
|
205
197
|
return this.releaseCore([...taskUrls]);
|
|
@@ -476,7 +468,7 @@ export class AgentSchedulerFactory implements IFluidDataStoreFactory {
|
|
|
476
468
|
|
|
477
469
|
public static async createChildInstance(
|
|
478
470
|
parentContext: IFluidDataStoreContext,
|
|
479
|
-
): Promise<
|
|
471
|
+
): Promise<IAgentScheduler> {
|
|
480
472
|
const packagePath = [...parentContext.packagePath, AgentSchedulerFactory.type];
|
|
481
473
|
const dataStore = await parentContext.containerRuntime.createDataStore(packagePath);
|
|
482
474
|
const entryPoint: FluidObject<IAgentScheduler> | undefined =
|
|
@@ -491,7 +483,10 @@ export class AgentSchedulerFactory implements IFluidDataStoreFactory {
|
|
|
491
483
|
return entryPoint as unknown as AgentScheduler;
|
|
492
484
|
}
|
|
493
485
|
|
|
494
|
-
public async instantiateDataStore(
|
|
486
|
+
public async instantiateDataStore(
|
|
487
|
+
context: IFluidDataStoreContext,
|
|
488
|
+
existing: boolean,
|
|
489
|
+
): Promise<FluidDataStoreRuntime> {
|
|
495
490
|
const mapFactory = SharedMap.getFactory();
|
|
496
491
|
const consensusRegisterCollectionFactory = ConsensusRegisterCollection.getFactory();
|
|
497
492
|
const dataTypes = new Map<string, IChannelFactory>();
|
package/src/taskSubscription.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { IEvent } from "@fluidframework/
|
|
7
|
-
import { TypedEventEmitter } from "@
|
|
6
|
+
import { IEvent } from "@fluidframework/core-interfaces";
|
|
7
|
+
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
8
8
|
import { IAgentScheduler } from "./agent";
|
|
9
9
|
|
|
10
10
|
export interface ITaskSubscriptionEvents extends IEvent {
|