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