@workglow/task-graph 0.0.57 → 0.0.58
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/browser.js +102 -51
- package/dist/browser.js.map +6 -6
- package/dist/bun.js +102 -51
- package/dist/bun.js.map +6 -6
- package/dist/node.js +102 -51
- package/dist/node.js.map +6 -6
- package/dist/task/JobQueueFactory.d.ts +27 -9
- package/dist/task/JobQueueFactory.d.ts.map +1 -1
- package/dist/task/JobQueueTask.d.ts +16 -5
- package/dist/task/JobQueueTask.d.ts.map +1 -1
- package/dist/task/Task.d.ts.map +1 -1
- package/dist/task/TaskJSON.test.d.ts +7 -0
- package/dist/task/TaskJSON.test.d.ts.map +1 -0
- package/dist/task/TaskQueueRegistry.d.ts +21 -12
- package/dist/task/TaskQueueRegistry.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/browser.js
CHANGED
|
@@ -779,6 +779,7 @@ class Task {
|
|
|
779
779
|
let json = this.stripSymbols({
|
|
780
780
|
id: this.config.id,
|
|
781
781
|
type: this.type,
|
|
782
|
+
...this.config.name ? { name: this.config.name } : {},
|
|
782
783
|
defaults: this.defaults,
|
|
783
784
|
...Object.keys(provenance).length ? { provenance } : {},
|
|
784
785
|
...extras && Object.keys(extras).length ? { extras } : {}
|
|
@@ -2400,27 +2401,70 @@ class ArrayTaskRunner extends GraphAsTaskRunner {
|
|
|
2400
2401
|
}
|
|
2401
2402
|
}
|
|
2402
2403
|
// src/task/JobQueueFactory.ts
|
|
2403
|
-
import {
|
|
2404
|
+
import {
|
|
2405
|
+
JobQueueClient,
|
|
2406
|
+
JobQueueServer
|
|
2407
|
+
} from "@workglow/job-queue";
|
|
2404
2408
|
import { InMemoryQueueStorage } from "@workglow/storage";
|
|
2405
2409
|
import { createServiceToken as createServiceToken2, globalServiceRegistry as globalServiceRegistry3 } from "@workglow/util";
|
|
2406
2410
|
var JOB_QUEUE_FACTORY = createServiceToken2("taskgraph.jobQueueFactory");
|
|
2407
|
-
var defaultJobQueueFactory = async ({
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2411
|
+
var defaultJobQueueFactory = async ({
|
|
2412
|
+
queueName,
|
|
2413
|
+
jobClass,
|
|
2414
|
+
options
|
|
2415
|
+
}) => {
|
|
2416
|
+
const storage = options?.storage ?? new InMemoryQueueStorage(queueName);
|
|
2417
|
+
await storage.setupDatabase();
|
|
2418
|
+
const server = new JobQueueServer(jobClass, {
|
|
2419
|
+
storage,
|
|
2420
|
+
queueName,
|
|
2421
|
+
limiter: options?.limiter,
|
|
2422
|
+
workerCount: options?.workerCount,
|
|
2423
|
+
pollIntervalMs: options?.pollIntervalMs,
|
|
2424
|
+
deleteAfterCompletionMs: options?.deleteAfterCompletionMs,
|
|
2425
|
+
deleteAfterFailureMs: options?.deleteAfterFailureMs,
|
|
2426
|
+
deleteAfterDisabledMs: options?.deleteAfterDisabledMs,
|
|
2427
|
+
cleanupIntervalMs: options?.cleanupIntervalMs
|
|
2428
|
+
});
|
|
2429
|
+
const client = new JobQueueClient({
|
|
2430
|
+
storage,
|
|
2431
|
+
queueName
|
|
2432
|
+
});
|
|
2433
|
+
client.attach(server);
|
|
2434
|
+
return { server, client, storage };
|
|
2413
2435
|
};
|
|
2414
2436
|
function registerJobQueueFactory(factory) {
|
|
2415
2437
|
globalServiceRegistry3.registerInstance(JOB_QUEUE_FACTORY, factory);
|
|
2416
2438
|
}
|
|
2417
|
-
function
|
|
2418
|
-
return ({
|
|
2439
|
+
function createJobQueueFactoryWithOptions(defaultOptions = {}) {
|
|
2440
|
+
return async ({
|
|
2441
|
+
queueName,
|
|
2442
|
+
jobClass,
|
|
2443
|
+
options
|
|
2444
|
+
}) => {
|
|
2419
2445
|
const mergedOptions = {
|
|
2420
2446
|
...defaultOptions,
|
|
2421
2447
|
...options ?? {}
|
|
2422
2448
|
};
|
|
2423
|
-
|
|
2449
|
+
const storage = mergedOptions.storage ?? new InMemoryQueueStorage(queueName);
|
|
2450
|
+
await storage.setupDatabase();
|
|
2451
|
+
const server = new JobQueueServer(jobClass, {
|
|
2452
|
+
storage,
|
|
2453
|
+
queueName,
|
|
2454
|
+
limiter: mergedOptions.limiter,
|
|
2455
|
+
workerCount: mergedOptions.workerCount,
|
|
2456
|
+
pollIntervalMs: mergedOptions.pollIntervalMs,
|
|
2457
|
+
deleteAfterCompletionMs: mergedOptions.deleteAfterCompletionMs,
|
|
2458
|
+
deleteAfterFailureMs: mergedOptions.deleteAfterFailureMs,
|
|
2459
|
+
deleteAfterDisabledMs: mergedOptions.deleteAfterDisabledMs,
|
|
2460
|
+
cleanupIntervalMs: mergedOptions.cleanupIntervalMs
|
|
2461
|
+
});
|
|
2462
|
+
const client = new JobQueueClient({
|
|
2463
|
+
storage,
|
|
2464
|
+
queueName
|
|
2465
|
+
});
|
|
2466
|
+
client.attach(server);
|
|
2467
|
+
return { server, client, storage };
|
|
2424
2468
|
};
|
|
2425
2469
|
}
|
|
2426
2470
|
function getJobQueueFactory() {
|
|
@@ -2440,30 +2484,31 @@ var taskQueueRegistry = null;
|
|
|
2440
2484
|
|
|
2441
2485
|
class TaskQueueRegistry {
|
|
2442
2486
|
queues = new Map;
|
|
2443
|
-
registerQueue(
|
|
2444
|
-
|
|
2445
|
-
|
|
2487
|
+
registerQueue(queue) {
|
|
2488
|
+
const queueName = queue.server.queueName;
|
|
2489
|
+
if (this.queues.has(queueName)) {
|
|
2490
|
+
throw new Error(`Queue with name ${queueName} already exists`);
|
|
2446
2491
|
}
|
|
2447
|
-
this.queues.set(
|
|
2492
|
+
this.queues.set(queueName, queue);
|
|
2448
2493
|
}
|
|
2449
|
-
getQueue(
|
|
2450
|
-
return this.queues.get(
|
|
2494
|
+
getQueue(queueName) {
|
|
2495
|
+
return this.queues.get(queueName);
|
|
2451
2496
|
}
|
|
2452
2497
|
startQueues() {
|
|
2453
2498
|
for (const queue of this.queues.values()) {
|
|
2454
|
-
queue.start();
|
|
2499
|
+
queue.server.start();
|
|
2455
2500
|
}
|
|
2456
2501
|
return this;
|
|
2457
2502
|
}
|
|
2458
2503
|
stopQueues() {
|
|
2459
2504
|
for (const queue of this.queues.values()) {
|
|
2460
|
-
queue.stop();
|
|
2505
|
+
queue.server.stop();
|
|
2461
2506
|
}
|
|
2462
2507
|
return this;
|
|
2463
2508
|
}
|
|
2464
2509
|
clearQueues() {
|
|
2465
2510
|
for (const queue of this.queues.values()) {
|
|
2466
|
-
queue.
|
|
2511
|
+
queue.storage.deleteAll();
|
|
2467
2512
|
}
|
|
2468
2513
|
return this;
|
|
2469
2514
|
}
|
|
@@ -2501,14 +2546,14 @@ class JobQueueTask extends ArrayTask {
|
|
|
2501
2546
|
if (this.config.queue === false && !this.constructor.canRunDirectly) {
|
|
2502
2547
|
throw new TaskConfigurationError(`${this.type} cannot run directly without a queue`);
|
|
2503
2548
|
}
|
|
2504
|
-
const
|
|
2505
|
-
|
|
2506
|
-
if (!queue) {
|
|
2549
|
+
const registeredQueue = await this.resolveQueue(input);
|
|
2550
|
+
if (!registeredQueue) {
|
|
2507
2551
|
if (!this.constructor.canRunDirectly) {
|
|
2508
2552
|
const queueLabel = typeof this.config.queue === "string" ? this.config.queue : this.currentQueueName ?? this.type;
|
|
2509
2553
|
throw new TaskConfigurationError(`Queue ${queueLabel} not found, and ${this.type} cannot run directly`);
|
|
2510
2554
|
}
|
|
2511
2555
|
this.currentJobId = undefined;
|
|
2556
|
+
const job = await this.createJob(input, this.currentQueueName);
|
|
2512
2557
|
cleanup = job.onJobProgress((progress, message, details) => {
|
|
2513
2558
|
executeContext.updateProgress(progress, message, details);
|
|
2514
2559
|
});
|
|
@@ -2518,14 +2563,18 @@ class JobQueueTask extends ArrayTask {
|
|
|
2518
2563
|
});
|
|
2519
2564
|
return output2;
|
|
2520
2565
|
}
|
|
2521
|
-
const
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2566
|
+
const { client } = registeredQueue;
|
|
2567
|
+
const jobInput = await this.getJobInput(input);
|
|
2568
|
+
const handle = await client.submit(jobInput, {
|
|
2569
|
+
jobRunId: this.currentRunnerId,
|
|
2570
|
+
maxRetries: 10
|
|
2571
|
+
});
|
|
2572
|
+
this.currentJobId = handle.id;
|
|
2573
|
+
this.currentQueueName = client.queueName;
|
|
2574
|
+
cleanup = handle.onProgress((progress, message, details) => {
|
|
2526
2575
|
executeContext.updateProgress(progress, message, details);
|
|
2527
2576
|
});
|
|
2528
|
-
const output = await
|
|
2577
|
+
const output = await handle.waitFor();
|
|
2529
2578
|
if (output === undefined) {
|
|
2530
2579
|
throw new TaskConfigurationError("Job disabled, should not happen");
|
|
2531
2580
|
}
|
|
@@ -2536,10 +2585,12 @@ class JobQueueTask extends ArrayTask {
|
|
|
2536
2585
|
cleanup();
|
|
2537
2586
|
}
|
|
2538
2587
|
}
|
|
2539
|
-
async
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2588
|
+
async getJobInput(input) {
|
|
2589
|
+
return input;
|
|
2590
|
+
}
|
|
2591
|
+
async createJob(input, queueName) {
|
|
2592
|
+
return new this.jobClass({
|
|
2593
|
+
queueName: queueName ?? this.currentQueueName,
|
|
2543
2594
|
jobRunId: this.currentRunnerId,
|
|
2544
2595
|
input
|
|
2545
2596
|
});
|
|
@@ -2551,10 +2602,10 @@ class JobQueueTask extends ArrayTask {
|
|
|
2551
2602
|
return;
|
|
2552
2603
|
}
|
|
2553
2604
|
if (typeof preference === "string") {
|
|
2554
|
-
const
|
|
2555
|
-
if (
|
|
2556
|
-
this.currentQueueName =
|
|
2557
|
-
return
|
|
2605
|
+
const registeredQueue2 = getTaskQueueRegistry().getQueue(preference);
|
|
2606
|
+
if (registeredQueue2) {
|
|
2607
|
+
this.currentQueueName = registeredQueue2.server.queueName;
|
|
2608
|
+
return registeredQueue2;
|
|
2558
2609
|
}
|
|
2559
2610
|
this.currentQueueName = preference;
|
|
2560
2611
|
return;
|
|
@@ -2565,19 +2616,19 @@ class JobQueueTask extends ArrayTask {
|
|
|
2565
2616
|
return;
|
|
2566
2617
|
}
|
|
2567
2618
|
this.currentQueueName = queueName;
|
|
2568
|
-
let
|
|
2569
|
-
if (!
|
|
2570
|
-
|
|
2571
|
-
await
|
|
2619
|
+
let registeredQueue = getTaskQueueRegistry().getQueue(queueName);
|
|
2620
|
+
if (!registeredQueue) {
|
|
2621
|
+
registeredQueue = await this.createAndRegisterQueue(queueName, input);
|
|
2622
|
+
await registeredQueue.server.start();
|
|
2572
2623
|
}
|
|
2573
|
-
return
|
|
2624
|
+
return registeredQueue;
|
|
2574
2625
|
}
|
|
2575
2626
|
async getDefaultQueueName(_input) {
|
|
2576
2627
|
return this.type;
|
|
2577
2628
|
}
|
|
2578
2629
|
async createAndRegisterQueue(queueName, input) {
|
|
2579
2630
|
const factory = getJobQueueFactory();
|
|
2580
|
-
let
|
|
2631
|
+
let registeredQueue = await factory({
|
|
2581
2632
|
queueName,
|
|
2582
2633
|
jobClass: this.jobClass,
|
|
2583
2634
|
input,
|
|
@@ -2586,24 +2637,24 @@ class JobQueueTask extends ArrayTask {
|
|
|
2586
2637
|
});
|
|
2587
2638
|
const registry = getTaskQueueRegistry();
|
|
2588
2639
|
try {
|
|
2589
|
-
registry.registerQueue(
|
|
2640
|
+
registry.registerQueue(registeredQueue);
|
|
2590
2641
|
} catch (err) {
|
|
2591
2642
|
if (err instanceof Error && err.message.includes("already exists")) {
|
|
2592
2643
|
const existing = registry.getQueue(queueName);
|
|
2593
2644
|
if (existing) {
|
|
2594
|
-
|
|
2645
|
+
registeredQueue = existing;
|
|
2595
2646
|
}
|
|
2596
2647
|
} else {
|
|
2597
2648
|
throw err;
|
|
2598
2649
|
}
|
|
2599
2650
|
}
|
|
2600
|
-
return
|
|
2651
|
+
return registeredQueue;
|
|
2601
2652
|
}
|
|
2602
2653
|
async abort() {
|
|
2603
|
-
if (this.currentQueueName) {
|
|
2604
|
-
const
|
|
2605
|
-
if (
|
|
2606
|
-
await
|
|
2654
|
+
if (this.currentQueueName && this.currentJobId) {
|
|
2655
|
+
const registeredQueue = getTaskQueueRegistry().getQueue(this.currentQueueName);
|
|
2656
|
+
if (registeredQueue) {
|
|
2657
|
+
await registeredQueue.client.abort(this.currentJobId);
|
|
2607
2658
|
}
|
|
2608
2659
|
}
|
|
2609
2660
|
super.abort();
|
|
@@ -2841,7 +2892,7 @@ export {
|
|
|
2841
2892
|
ensureTask,
|
|
2842
2893
|
createTaskFromGraphJSON,
|
|
2843
2894
|
createTaskFromDependencyJSON,
|
|
2844
|
-
|
|
2895
|
+
createJobQueueFactoryWithOptions,
|
|
2845
2896
|
createGraphFromGraphJSON,
|
|
2846
2897
|
createGraphFromDependencyJSON,
|
|
2847
2898
|
connect,
|
|
@@ -2887,4 +2938,4 @@ export {
|
|
|
2887
2938
|
ArrayTask
|
|
2888
2939
|
};
|
|
2889
2940
|
|
|
2890
|
-
//# debugId=
|
|
2941
|
+
//# debugId=662106DD09E8768F64756E2164756E21
|