@spooled/sdk 1.0.34 → 1.0.35

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.
@@ -107,11 +107,11 @@ declare const DEFAULT_CONFIG: {
107
107
  successThreshold: number;
108
108
  timeout: number;
109
109
  };
110
- readonly userAgent: "@spooled/sdk-nodejs/1.0.33";
110
+ readonly userAgent: "@spooled/sdk-nodejs/1.0.35";
111
111
  readonly autoRefreshToken: true;
112
112
  };
113
113
  /** SDK version */
114
- declare const SDK_VERSION = "1.0.33";
114
+ declare const SDK_VERSION = "1.0.35";
115
115
  /** API version prefix */
116
116
  declare const API_VERSION = "v1";
117
117
  /**
@@ -559,7 +559,7 @@ interface Job {
559
559
  parentJobId?: string;
560
560
  completionWebhook?: string;
561
561
  assignedWorkerId?: string;
562
- leaseId?: string;
562
+ leaseId?: string | null;
563
563
  leaseExpiresAt?: string;
564
564
  idempotencyKey?: string;
565
565
  updatedAt: string;
@@ -653,7 +653,7 @@ interface ClaimedJob {
653
653
  * worker actually holds (backend rejects stale leases with 409
654
654
  * LEASE_EXPIRED). Omitted = legacy behavior.
655
655
  */
656
- leaseId?: string;
656
+ leaseId?: string | null;
657
657
  }
658
658
  /** Parameters for claiming jobs */
659
659
  interface ClaimJobsParams {
@@ -2620,7 +2620,7 @@ interface GrpcJob {
2620
2620
  * in Complete/Fail/RenewLease so the operation applies only to the lease
2621
2621
  * this worker actually holds (empty = legacy worker_id fence).
2622
2622
  */
2623
- leaseId?: string;
2623
+ leaseId?: string | null;
2624
2624
  }
2625
2625
  /** Enqueue request */
2626
2626
  interface GrpcEnqueueRequest {
@@ -3369,6 +3369,7 @@ interface WorkerEventData {
3369
3369
  }
3370
3370
  /** Active job tracking */
3371
3371
  interface ActiveJob {
3372
+ readonly executionId: symbol;
3372
3373
  job: ClaimedJob;
3373
3374
  startedAt: Date;
3374
3375
  heartbeatTimer?: ReturnType<typeof setInterval>;
@@ -107,11 +107,11 @@ declare const DEFAULT_CONFIG: {
107
107
  successThreshold: number;
108
108
  timeout: number;
109
109
  };
110
- readonly userAgent: "@spooled/sdk-nodejs/1.0.33";
110
+ readonly userAgent: "@spooled/sdk-nodejs/1.0.35";
111
111
  readonly autoRefreshToken: true;
112
112
  };
113
113
  /** SDK version */
114
- declare const SDK_VERSION = "1.0.33";
114
+ declare const SDK_VERSION = "1.0.35";
115
115
  /** API version prefix */
116
116
  declare const API_VERSION = "v1";
117
117
  /**
@@ -559,7 +559,7 @@ interface Job {
559
559
  parentJobId?: string;
560
560
  completionWebhook?: string;
561
561
  assignedWorkerId?: string;
562
- leaseId?: string;
562
+ leaseId?: string | null;
563
563
  leaseExpiresAt?: string;
564
564
  idempotencyKey?: string;
565
565
  updatedAt: string;
@@ -653,7 +653,7 @@ interface ClaimedJob {
653
653
  * worker actually holds (backend rejects stale leases with 409
654
654
  * LEASE_EXPIRED). Omitted = legacy behavior.
655
655
  */
656
- leaseId?: string;
656
+ leaseId?: string | null;
657
657
  }
658
658
  /** Parameters for claiming jobs */
659
659
  interface ClaimJobsParams {
@@ -2620,7 +2620,7 @@ interface GrpcJob {
2620
2620
  * in Complete/Fail/RenewLease so the operation applies only to the lease
2621
2621
  * this worker actually holds (empty = legacy worker_id fence).
2622
2622
  */
2623
- leaseId?: string;
2623
+ leaseId?: string | null;
2624
2624
  }
2625
2625
  /** Enqueue request */
2626
2626
  interface GrpcEnqueueRequest {
@@ -3369,6 +3369,7 @@ interface WorkerEventData {
3369
3369
  }
3370
3370
  /** Active job tracking */
3371
3371
  interface ActiveJob {
3372
+ readonly executionId: symbol;
3372
3373
  job: ClaimedJob;
3373
3374
  startedAt: Date;
3374
3375
  heartbeatTimer?: ReturnType<typeof setInterval>;
package/dist/index.cjs CHANGED
@@ -49,10 +49,10 @@ var DEFAULT_CONFIG = {
49
49
  successThreshold: 3,
50
50
  timeout: 3e4
51
51
  },
52
- userAgent: "@spooled/sdk-nodejs/1.0.33",
52
+ userAgent: "@spooled/sdk-nodejs/1.0.35",
53
53
  autoRefreshToken: true
54
54
  };
55
- var SDK_VERSION = "1.0.33";
55
+ var SDK_VERSION = "1.0.35";
56
56
  var API_VERSION = "v1";
57
57
  var API_BASE_PATH = `/api/${API_VERSION}`;
58
58
  function normalizeCredential(value) {
@@ -3288,7 +3288,7 @@ var SpooledWorker = class {
3288
3288
  ...DEFAULT_OPTIONS,
3289
3289
  hostname: os.hostname(),
3290
3290
  workerType: "nodejs",
3291
- version: "1.0.34",
3291
+ version: SDK_VERSION,
3292
3292
  metadata: {},
3293
3293
  ...options
3294
3294
  };
@@ -3395,11 +3395,11 @@ var SpooledWorker = class {
3395
3395
  this.waitForActiveJobs(),
3396
3396
  this.sleep(this.options.shutdownTimeout)
3397
3397
  ]);
3398
- const remaining = Array.from(this.activeJobs.entries());
3399
- for (const [jobId, active] of remaining) {
3400
- this.debug(`Force-failing job ${jobId} due to shutdown timeout`);
3398
+ const remaining = Array.from(this.activeJobs.values());
3399
+ for (const active of remaining) {
3400
+ this.debug(`Force-failing job ${active.job.id} due to shutdown timeout`);
3401
3401
  await this.failJob(active.job, "Worker shutdown timeout");
3402
- this.cleanupJob(jobId);
3402
+ this.cleanupJob(active);
3403
3403
  }
3404
3404
  }
3405
3405
  if (this.workerId) {
@@ -3482,14 +3482,15 @@ var SpooledWorker = class {
3482
3482
  this.emit("job:claimed", { jobId: job.id, queueName: job.queueName });
3483
3483
  const abortController = new AbortController();
3484
3484
  const activeJob = {
3485
+ executionId: Symbol(job.id),
3485
3486
  job,
3486
3487
  startedAt: /* @__PURE__ */ new Date(),
3487
3488
  abortController
3488
3489
  };
3489
- this.activeJobs.set(job.id, activeJob);
3490
+ this.activeJobs.set(activeJob.executionId, activeJob);
3490
3491
  const heartbeatInterval = this.options.leaseDuration * this.options.heartbeatFraction * 1e3;
3491
3492
  activeJob.heartbeatTimer = setInterval(() => {
3492
- this.sendJobHeartbeat(job.id);
3493
+ this.sendJobHeartbeat(activeJob);
3493
3494
  }, heartbeatInterval);
3494
3495
  this.executeHandler(activeJob);
3495
3496
  }
@@ -3525,7 +3526,7 @@ var SpooledWorker = class {
3525
3526
  const errorMessage = error instanceof Error ? error.message : String(error);
3526
3527
  await this.failJob(job, errorMessage);
3527
3528
  } finally {
3528
- this.cleanupJob(job.id);
3529
+ this.cleanupJob(activeJob);
3529
3530
  }
3530
3531
  }
3531
3532
  async completeJob(job, result) {
@@ -3534,7 +3535,7 @@ var SpooledWorker = class {
3534
3535
  await this.client.jobs.complete(job.id, {
3535
3536
  workerId: this.workerId,
3536
3537
  result,
3537
- ...job.leaseId !== void 0 && { leaseId: job.leaseId }
3538
+ ...job.leaseId != null && { leaseId: job.leaseId }
3538
3539
  });
3539
3540
  this.emit("job:completed", {
3540
3541
  jobId: job.id,
@@ -3552,7 +3553,7 @@ var SpooledWorker = class {
3552
3553
  await this.client.jobs.fail(job.id, {
3553
3554
  workerId: this.workerId,
3554
3555
  error: errorMessage,
3555
- ...job.leaseId !== void 0 && { leaseId: job.leaseId }
3556
+ ...job.leaseId != null && { leaseId: job.leaseId }
3556
3557
  });
3557
3558
  this.emit("job:failed", {
3558
3559
  jobId: job.id,
@@ -3564,24 +3565,26 @@ var SpooledWorker = class {
3564
3565
  this.debug(`Failed to fail job ${job.id}`, error);
3565
3566
  }
3566
3567
  }
3567
- cleanupJob(jobId) {
3568
- const activeJob = this.activeJobs.get(jobId);
3569
- if (activeJob?.heartbeatTimer) {
3568
+ cleanupJob(activeJob) {
3569
+ if (activeJob.heartbeatTimer) {
3570
3570
  clearInterval(activeJob.heartbeatTimer);
3571
+ activeJob.heartbeatTimer = void 0;
3572
+ }
3573
+ if (this.activeJobs.get(activeJob.executionId) === activeJob) {
3574
+ this.activeJobs.delete(activeJob.executionId);
3571
3575
  }
3572
- this.activeJobs.delete(jobId);
3573
3576
  }
3574
- async sendJobHeartbeat(jobId) {
3577
+ async sendJobHeartbeat(activeJob) {
3575
3578
  if (!this.workerId) return;
3576
- const leaseId = this.activeJobs.get(jobId)?.job.leaseId;
3579
+ const { job } = activeJob;
3577
3580
  try {
3578
- await this.client.jobs.heartbeat(jobId, {
3581
+ await this.client.jobs.heartbeat(job.id, {
3579
3582
  workerId: this.workerId,
3580
3583
  leaseDurationSecs: this.options.leaseDuration,
3581
- ...leaseId !== void 0 && { leaseId }
3584
+ ...job.leaseId != null && { leaseId: job.leaseId }
3582
3585
  });
3583
3586
  } catch (error) {
3584
- this.debug(`Job heartbeat failed for ${jobId}`, error);
3587
+ this.debug(`Job heartbeat failed for ${job.id}`, error);
3585
3588
  }
3586
3589
  }
3587
3590
  async sendWorkerHeartbeat() {