@workglow/job-queue 0.0.69 → 0.0.71
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/README.md +0 -4
- package/dist/browser.js +77 -141
- package/dist/browser.js.map +7 -6
- package/dist/bun.js +77 -141
- package/dist/bun.js.map +7 -6
- package/dist/common.d.ts +1 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/job/JobQueueClient.d.ts +7 -0
- package/dist/job/JobQueueClient.d.ts.map +1 -1
- package/dist/job/JobQueueEventListeners.d.ts +0 -2
- package/dist/job/JobQueueEventListeners.d.ts.map +1 -1
- package/dist/job/JobQueueServer.d.ts +0 -1
- package/dist/job/JobQueueServer.d.ts.map +1 -1
- package/dist/job/JobQueueWorker.d.ts.map +1 -1
- package/dist/job/JobStorageConverters.d.ts +18 -0
- package/dist/job/JobStorageConverters.d.ts.map +1 -0
- package/dist/node.js +77 -141
- package/dist/node.js.map +7 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -417,10 +417,6 @@ server.on("server_stop", (queueName) => {
|
|
|
417
417
|
console.log(`Server ${queueName} stopped`);
|
|
418
418
|
});
|
|
419
419
|
|
|
420
|
-
server.on("stats_update", (queueName, stats) => {
|
|
421
|
-
console.log(`Queue stats:`, stats);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
420
|
// Wait for specific events
|
|
425
421
|
const [queueName, jobId, output] = await client.waitOn("job_complete");
|
|
426
422
|
```
|
package/dist/browser.js
CHANGED
|
@@ -136,6 +136,71 @@ class Job {
|
|
|
136
136
|
// src/job/JobQueueClient.ts
|
|
137
137
|
import { JobStatus as JobStatus2 } from "@workglow/storage";
|
|
138
138
|
import { EventEmitter } from "@workglow/util";
|
|
139
|
+
|
|
140
|
+
// src/job/JobStorageConverters.ts
|
|
141
|
+
function toDate(date) {
|
|
142
|
+
if (!date)
|
|
143
|
+
return null;
|
|
144
|
+
const d = new Date(date);
|
|
145
|
+
return isNaN(d.getTime()) ? null : d;
|
|
146
|
+
}
|
|
147
|
+
function dateToISOString(date) {
|
|
148
|
+
if (!date)
|
|
149
|
+
return null;
|
|
150
|
+
return isNaN(date.getTime()) ? null : date.toISOString();
|
|
151
|
+
}
|
|
152
|
+
function storageToClass(details, jobClass, options) {
|
|
153
|
+
const includeWorkerId = options?.includeWorkerId ?? true;
|
|
154
|
+
return new jobClass({
|
|
155
|
+
id: details.id,
|
|
156
|
+
jobRunId: details.job_run_id,
|
|
157
|
+
queueName: details.queue,
|
|
158
|
+
fingerprint: details.fingerprint,
|
|
159
|
+
input: details.input,
|
|
160
|
+
output: details.output,
|
|
161
|
+
runAfter: toDate(details.run_after),
|
|
162
|
+
createdAt: toDate(details.created_at),
|
|
163
|
+
deadlineAt: toDate(details.deadline_at),
|
|
164
|
+
lastRanAt: toDate(details.last_ran_at),
|
|
165
|
+
completedAt: toDate(details.completed_at),
|
|
166
|
+
progress: details.progress || 0,
|
|
167
|
+
progressMessage: details.progress_message || "",
|
|
168
|
+
progressDetails: details.progress_details ?? null,
|
|
169
|
+
status: details.status,
|
|
170
|
+
error: details.error ?? null,
|
|
171
|
+
errorCode: details.error_code ?? null,
|
|
172
|
+
runAttempts: details.run_attempts ?? 0,
|
|
173
|
+
maxRetries: details.max_retries ?? 10,
|
|
174
|
+
...includeWorkerId ? { workerId: details.worker_id ?? null } : {}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function classToStorage(job, queueName) {
|
|
178
|
+
const now = new Date().toISOString();
|
|
179
|
+
return {
|
|
180
|
+
id: job.id,
|
|
181
|
+
job_run_id: job.jobRunId,
|
|
182
|
+
queue: job.queueName || queueName,
|
|
183
|
+
fingerprint: job.fingerprint,
|
|
184
|
+
input: job.input,
|
|
185
|
+
status: job.status,
|
|
186
|
+
output: job.output ?? null,
|
|
187
|
+
error: job.error === null ? null : String(job.error),
|
|
188
|
+
error_code: job.errorCode || null,
|
|
189
|
+
run_attempts: job.runAttempts ?? 0,
|
|
190
|
+
max_retries: job.maxRetries ?? 10,
|
|
191
|
+
run_after: dateToISOString(job.runAfter) ?? now,
|
|
192
|
+
created_at: dateToISOString(job.createdAt) ?? now,
|
|
193
|
+
deadline_at: dateToISOString(job.deadlineAt),
|
|
194
|
+
last_ran_at: dateToISOString(job.lastRanAt),
|
|
195
|
+
completed_at: dateToISOString(job.completedAt),
|
|
196
|
+
progress: job.progress ?? 0,
|
|
197
|
+
progress_message: job.progressMessage ?? "",
|
|
198
|
+
progress_details: job.progressDetails ?? null,
|
|
199
|
+
worker_id: job.workerId ?? null
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/job/JobQueueClient.ts
|
|
139
204
|
class JobQueueClient {
|
|
140
205
|
queueName;
|
|
141
206
|
storage;
|
|
@@ -266,7 +331,7 @@ class JobQueueClient {
|
|
|
266
331
|
throw new JobNotFoundError("Cannot abort job run with undefined jobRunId");
|
|
267
332
|
const jobs = await this.getJobsByRunId(jobRunId);
|
|
268
333
|
await Promise.allSettled(jobs.map((job) => {
|
|
269
|
-
if (
|
|
334
|
+
if (job.status === JobStatus2.PROCESSING || job.status === JobStatus2.PENDING) {
|
|
270
335
|
return this.abort(job.id);
|
|
271
336
|
}
|
|
272
337
|
}));
|
|
@@ -299,6 +364,9 @@ class JobQueueClient {
|
|
|
299
364
|
waitOn(event) {
|
|
300
365
|
return this.events.waitOn(event);
|
|
301
366
|
}
|
|
367
|
+
subscribe(event, listener) {
|
|
368
|
+
return this.events.subscribe(event, listener);
|
|
369
|
+
}
|
|
302
370
|
handleJobStart(jobId) {
|
|
303
371
|
this.lastKnownProgress.set(jobId, {
|
|
304
372
|
progress: 0,
|
|
@@ -388,33 +456,7 @@ class JobQueueClient {
|
|
|
388
456
|
}
|
|
389
457
|
}
|
|
390
458
|
storageToClass(details) {
|
|
391
|
-
|
|
392
|
-
if (!date)
|
|
393
|
-
return null;
|
|
394
|
-
const d = new Date(date);
|
|
395
|
-
return isNaN(d.getTime()) ? null : d;
|
|
396
|
-
};
|
|
397
|
-
return new Job({
|
|
398
|
-
id: details.id,
|
|
399
|
-
jobRunId: details.job_run_id,
|
|
400
|
-
queueName: details.queue,
|
|
401
|
-
fingerprint: details.fingerprint,
|
|
402
|
-
input: details.input,
|
|
403
|
-
output: details.output,
|
|
404
|
-
runAfter: toDate(details.run_after),
|
|
405
|
-
createdAt: toDate(details.created_at),
|
|
406
|
-
deadlineAt: toDate(details.deadline_at),
|
|
407
|
-
lastRanAt: toDate(details.last_ran_at),
|
|
408
|
-
completedAt: toDate(details.completed_at),
|
|
409
|
-
progress: details.progress || 0,
|
|
410
|
-
progressMessage: details.progress_message || "",
|
|
411
|
-
progressDetails: details.progress_details ?? null,
|
|
412
|
-
status: details.status,
|
|
413
|
-
error: details.error ?? null,
|
|
414
|
-
errorCode: details.error_code ?? null,
|
|
415
|
-
runAttempts: details.run_attempts ?? 0,
|
|
416
|
-
maxRetries: details.max_retries ?? 10
|
|
417
|
-
});
|
|
459
|
+
return storageToClass(details, Job, { includeWorkerId: true });
|
|
418
460
|
}
|
|
419
461
|
buildErrorFromJob(job) {
|
|
420
462
|
return this.buildErrorFromCode(job.error || "Job failed", job.errorCode ?? undefined);
|
|
@@ -736,64 +778,10 @@ class JobQueueWorker {
|
|
|
736
778
|
this.activeJobAbortControllers.delete(jobId);
|
|
737
779
|
}
|
|
738
780
|
storageToClass(details) {
|
|
739
|
-
|
|
740
|
-
if (!date)
|
|
741
|
-
return null;
|
|
742
|
-
const d = new Date(date);
|
|
743
|
-
return isNaN(d.getTime()) ? null : d;
|
|
744
|
-
};
|
|
745
|
-
return new this.jobClass({
|
|
746
|
-
id: details.id,
|
|
747
|
-
jobRunId: details.job_run_id,
|
|
748
|
-
queueName: details.queue,
|
|
749
|
-
fingerprint: details.fingerprint,
|
|
750
|
-
input: details.input,
|
|
751
|
-
output: details.output,
|
|
752
|
-
runAfter: toDate(details.run_after),
|
|
753
|
-
createdAt: toDate(details.created_at),
|
|
754
|
-
deadlineAt: toDate(details.deadline_at),
|
|
755
|
-
lastRanAt: toDate(details.last_ran_at),
|
|
756
|
-
completedAt: toDate(details.completed_at),
|
|
757
|
-
progress: details.progress || 0,
|
|
758
|
-
progressMessage: details.progress_message || "",
|
|
759
|
-
progressDetails: details.progress_details ?? null,
|
|
760
|
-
status: details.status,
|
|
761
|
-
error: details.error ?? null,
|
|
762
|
-
errorCode: details.error_code ?? null,
|
|
763
|
-
runAttempts: details.run_attempts ?? 0,
|
|
764
|
-
maxRetries: details.max_retries ?? 10,
|
|
765
|
-
workerId: details.worker_id ?? null
|
|
766
|
-
});
|
|
781
|
+
return storageToClass(details, this.jobClass);
|
|
767
782
|
}
|
|
768
783
|
classToStorage(job) {
|
|
769
|
-
|
|
770
|
-
if (!date)
|
|
771
|
-
return null;
|
|
772
|
-
return isNaN(date.getTime()) ? null : date.toISOString();
|
|
773
|
-
};
|
|
774
|
-
const now = new Date().toISOString();
|
|
775
|
-
return {
|
|
776
|
-
id: job.id,
|
|
777
|
-
job_run_id: job.jobRunId,
|
|
778
|
-
queue: job.queueName || this.queueName,
|
|
779
|
-
fingerprint: job.fingerprint,
|
|
780
|
-
input: job.input,
|
|
781
|
-
status: job.status,
|
|
782
|
-
output: job.output ?? null,
|
|
783
|
-
error: job.error === null ? null : String(job.error),
|
|
784
|
-
error_code: job.errorCode || null,
|
|
785
|
-
run_attempts: job.runAttempts ?? 0,
|
|
786
|
-
max_retries: job.maxRetries ?? 10,
|
|
787
|
-
run_after: dateToISOString(job.runAfter) ?? now,
|
|
788
|
-
created_at: dateToISOString(job.createdAt) ?? now,
|
|
789
|
-
deadline_at: dateToISOString(job.deadlineAt),
|
|
790
|
-
last_ran_at: dateToISOString(job.lastRanAt),
|
|
791
|
-
completed_at: dateToISOString(job.completedAt),
|
|
792
|
-
progress: job.progress ?? 0,
|
|
793
|
-
progress_message: job.progressMessage ?? "",
|
|
794
|
-
progress_details: job.progressDetails ?? null,
|
|
795
|
-
worker_id: job.workerId ?? null
|
|
796
|
-
};
|
|
784
|
+
return classToStorage(job, this.queueName);
|
|
797
785
|
}
|
|
798
786
|
}
|
|
799
787
|
|
|
@@ -1037,64 +1025,10 @@ class JobQueueServer {
|
|
|
1037
1025
|
}
|
|
1038
1026
|
}
|
|
1039
1027
|
storageToClass(details) {
|
|
1040
|
-
|
|
1041
|
-
if (!date)
|
|
1042
|
-
return null;
|
|
1043
|
-
const d = new Date(date);
|
|
1044
|
-
return isNaN(d.getTime()) ? null : d;
|
|
1045
|
-
};
|
|
1046
|
-
return new this.jobClass({
|
|
1047
|
-
id: details.id,
|
|
1048
|
-
jobRunId: details.job_run_id,
|
|
1049
|
-
queueName: details.queue,
|
|
1050
|
-
fingerprint: details.fingerprint,
|
|
1051
|
-
input: details.input,
|
|
1052
|
-
output: details.output,
|
|
1053
|
-
runAfter: toDate(details.run_after),
|
|
1054
|
-
createdAt: toDate(details.created_at),
|
|
1055
|
-
deadlineAt: toDate(details.deadline_at),
|
|
1056
|
-
lastRanAt: toDate(details.last_ran_at),
|
|
1057
|
-
completedAt: toDate(details.completed_at),
|
|
1058
|
-
progress: details.progress || 0,
|
|
1059
|
-
progressMessage: details.progress_message || "",
|
|
1060
|
-
progressDetails: details.progress_details ?? null,
|
|
1061
|
-
status: details.status,
|
|
1062
|
-
error: details.error ?? null,
|
|
1063
|
-
errorCode: details.error_code ?? null,
|
|
1064
|
-
runAttempts: details.run_attempts ?? 0,
|
|
1065
|
-
maxRetries: details.max_retries ?? 10,
|
|
1066
|
-
workerId: details.worker_id ?? null
|
|
1067
|
-
});
|
|
1028
|
+
return storageToClass(details, this.jobClass);
|
|
1068
1029
|
}
|
|
1069
1030
|
classToStorage(job) {
|
|
1070
|
-
|
|
1071
|
-
if (!date)
|
|
1072
|
-
return null;
|
|
1073
|
-
return isNaN(date.getTime()) ? null : date.toISOString();
|
|
1074
|
-
};
|
|
1075
|
-
const now = new Date().toISOString();
|
|
1076
|
-
return {
|
|
1077
|
-
id: job.id,
|
|
1078
|
-
job_run_id: job.jobRunId,
|
|
1079
|
-
queue: job.queueName || this.queueName,
|
|
1080
|
-
fingerprint: job.fingerprint,
|
|
1081
|
-
input: job.input,
|
|
1082
|
-
status: job.status,
|
|
1083
|
-
output: job.output ?? null,
|
|
1084
|
-
error: job.error === null ? null : String(job.error),
|
|
1085
|
-
error_code: job.errorCode || null,
|
|
1086
|
-
run_attempts: job.runAttempts ?? 0,
|
|
1087
|
-
max_retries: job.maxRetries ?? 10,
|
|
1088
|
-
run_after: dateToISOString(job.runAfter) ?? now,
|
|
1089
|
-
created_at: dateToISOString(job.createdAt) ?? now,
|
|
1090
|
-
deadline_at: dateToISOString(job.deadlineAt),
|
|
1091
|
-
last_ran_at: dateToISOString(job.lastRanAt),
|
|
1092
|
-
completed_at: dateToISOString(job.completedAt),
|
|
1093
|
-
progress: job.progress ?? 0,
|
|
1094
|
-
progress_message: job.progressMessage ?? "",
|
|
1095
|
-
progress_details: job.progressDetails ?? null,
|
|
1096
|
-
worker_id: job.workerId ?? null
|
|
1097
|
-
};
|
|
1031
|
+
return classToStorage(job, this.queueName);
|
|
1098
1032
|
}
|
|
1099
1033
|
getWorkerIds() {
|
|
1100
1034
|
return this.workers.map((worker) => worker.workerId);
|
|
@@ -1377,6 +1311,8 @@ class RateLimiter {
|
|
|
1377
1311
|
}
|
|
1378
1312
|
}
|
|
1379
1313
|
export {
|
|
1314
|
+
storageToClass,
|
|
1315
|
+
classToStorage,
|
|
1380
1316
|
RetryableJobError,
|
|
1381
1317
|
RateLimiter,
|
|
1382
1318
|
PermanentJobError,
|
|
@@ -1400,4 +1336,4 @@ export {
|
|
|
1400
1336
|
AbortSignalJobError
|
|
1401
1337
|
};
|
|
1402
1338
|
|
|
1403
|
-
//# debugId=
|
|
1339
|
+
//# debugId=0791E387717537CD64756E2164756E21
|