@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/bun.js CHANGED
@@ -780,6 +780,7 @@ class Task {
780
780
  let json = this.stripSymbols({
781
781
  id: this.config.id,
782
782
  type: this.type,
783
+ ...this.config.name ? { name: this.config.name } : {},
783
784
  defaults: this.defaults,
784
785
  ...Object.keys(provenance).length ? { provenance } : {},
785
786
  ...extras && Object.keys(extras).length ? { extras } : {}
@@ -2401,27 +2402,70 @@ class ArrayTaskRunner extends GraphAsTaskRunner {
2401
2402
  }
2402
2403
  }
2403
2404
  // src/task/JobQueueFactory.ts
2404
- import { JobQueue } from "@workglow/job-queue";
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 ({ queueName, jobClass, options }) => {
2409
- const queueOptions = {
2410
- ...options ?? {}
2411
- };
2412
- queueOptions.storage ??= new InMemoryQueueStorage(queueName);
2413
- return new JobQueue(queueName, jobClass, queueOptions);
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 createJobQueueFactoryFromClass(QueueCtor, defaultOptions = {}) {
2419
- return ({ queueName, jobClass, options }) => {
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
- return new QueueCtor(queueName, jobClass, mergedOptions);
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(jobQueue) {
2445
- if (this.queues.has(jobQueue.queueName)) {
2446
- throw new Error(`Queue with name ${jobQueue.queueName} already exists`);
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(jobQueue.queueName, jobQueue);
2493
+ this.queues.set(queueName, queue);
2449
2494
  }
2450
- getQueue(queue) {
2451
- return this.queues.get(queue);
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.clear();
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 queue = await this.resolveQueue(input);
2506
- const job = await this.createJob(input, queue);
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 jobId = await queue.add(job);
2523
- this.currentJobId = jobId;
2524
- this.currentQueueName = queue?.queueName;
2525
- this.currentRunnerId = job.jobRunId;
2526
- cleanup = queue.onJobProgress(jobId, (progress, message, details) => {
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 queue.waitFor(jobId);
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 createJob(input, queue) {
2541
- const jobCtor = queue?.jobClass ?? this.jobClass;
2542
- return new jobCtor({
2543
- queueName: queue?.queueName ?? this.currentQueueName,
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 queue2 = getTaskQueueRegistry().getQueue(preference);
2556
- if (queue2) {
2557
- this.currentQueueName = queue2.queueName;
2558
- return queue2;
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 queue = getTaskQueueRegistry().getQueue(queueName);
2570
- if (!queue) {
2571
- queue = await this.createAndRegisterQueue(queueName, input);
2572
- await queue.start();
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 queue;
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 queue = await factory({
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(queue);
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
- queue = existing;
2646
+ registeredQueue = existing;
2596
2647
  }
2597
2648
  } else {
2598
2649
  throw err;
2599
2650
  }
2600
2651
  }
2601
- return queue;
2652
+ return registeredQueue;
2602
2653
  }
2603
2654
  async abort() {
2604
- if (this.currentQueueName) {
2605
- const queue = getTaskQueueRegistry().getQueue(this.currentQueueName);
2606
- if (queue) {
2607
- await queue.abort(this.currentJobId);
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();
@@ -2842,7 +2893,7 @@ export {
2842
2893
  ensureTask,
2843
2894
  createTaskFromGraphJSON,
2844
2895
  createTaskFromDependencyJSON,
2845
- createJobQueueFactoryFromClass,
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=D3EC2E99FF734C2C64756E2164756E21
2942
+ //# debugId=54877F3DCD961A9A64756E2164756E21