cairnq 0.9.0 → 0.11.0
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 +10 -2
- package/dist/_protocol/migrations/postgres/0001_init.sql +2 -0
- package/dist/_protocol/migrations/postgres/0006_claim_name_index.sql +2 -0
- package/dist/_protocol/migrations/postgres/0008_claim_due_index.sql +68 -0
- package/dist/_protocol/migrations/sqlite/0001_init.sql +2 -0
- package/dist/_protocol/migrations/sqlite/0006_claim_name_index.sql +2 -0
- package/dist/_protocol/migrations/sqlite/0008_claim_due_index.sql +84 -0
- package/dist/_protocol/sql/postgres/claim.sql +6 -3
- package/dist/_protocol/sql/postgres/claim_one_name.sql +6 -3
- package/dist/_protocol/sql/postgres/claim_one_queue.sql +9 -5
- package/dist/_protocol/sql/postgres/claim_one_queue_one_name.sql +6 -3
- package/dist/_protocol/sql/postgres/installations.sql +33 -0
- package/dist/_protocol/sql/sqlite/claim.sql +6 -3
- package/dist/_protocol/sql/sqlite/claim_one_name.sql +6 -3
- package/dist/_protocol/sql/sqlite/claim_one_queue.sql +9 -6
- package/dist/_protocol/sql/sqlite/claim_one_queue_one_name.sql +9 -4
- package/dist/context.d.ts +4 -2
- package/dist/context.js +12 -8
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +34 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models.d.ts +2 -0
- package/dist/models.js +28 -1
- package/dist/retention.d.ts +13 -1
- package/dist/retention.js +26 -11
- package/dist/store/base.d.ts +12 -3
- package/dist/store/base.js +21 -6
- package/dist/store/pg-executor.d.ts +6 -5
- package/dist/store/pg-executor.js +6 -5
- package/dist/store/pg-pool.js +37 -11
- package/dist/store/postgres.d.ts +64 -0
- package/dist/store/postgres.js +121 -1
- package/dist/worker.d.ts +4 -2
- package/dist/worker.js +10 -8
- package/package.json +1 -1
- package/src/context.ts +10 -6
- package/src/errors.ts +36 -0
- package/src/index.ts +2 -0
- package/src/models.ts +28 -1
- package/src/retention.ts +27 -11
- package/src/store/base.ts +27 -5
- package/src/store/pg-executor.ts +6 -5
- package/src/store/pg-pool.ts +38 -11
- package/src/store/postgres.ts +125 -1
- package/src/worker.ts +10 -8
package/src/worker.ts
CHANGED
|
@@ -222,7 +222,7 @@ function release(counts: Map<string, number>, key: string | undefined): void {
|
|
|
222
222
|
|
|
223
223
|
export class Worker {
|
|
224
224
|
private readonly handlers = new Map<string, Registration>();
|
|
225
|
-
private readonly
|
|
225
|
+
private readonly ownId = newId("worker");
|
|
226
226
|
/** Payload bytes charged to running handlers — see maxInFlightBytes. */
|
|
227
227
|
private inFlightBytes = 0;
|
|
228
228
|
/** Calls in flight, for the names that cap their own concurrency. */
|
|
@@ -305,8 +305,10 @@ export class Worker {
|
|
|
305
305
|
return worker;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
/** This worker's id — what `worker_id` on a running task points at, and what
|
|
309
|
+
* the Python SDK calls `worker_id` too. */
|
|
310
|
+
get workerId(): string {
|
|
311
|
+
return this.ownId;
|
|
310
312
|
}
|
|
311
313
|
|
|
312
314
|
task(handler: Handler): this;
|
|
@@ -474,7 +476,7 @@ export class Worker {
|
|
|
474
476
|
}
|
|
475
477
|
|
|
476
478
|
private context(task: Task, leaseMs: number): TaskContext {
|
|
477
|
-
return new TaskContext(this.store, task, this.
|
|
479
|
+
return new TaskContext(this.store, task, this.ownId, leaseMs, {
|
|
478
480
|
retryBackoffMs: this.backoffMs,
|
|
479
481
|
retryBackoffMaxMs: this.backoffMaxMs,
|
|
480
482
|
});
|
|
@@ -588,7 +590,7 @@ export class Worker {
|
|
|
588
590
|
// Only what this worker can run. Queues do not partition work by task
|
|
589
591
|
// name, so another worker's tasks would otherwise be claimed here and
|
|
590
592
|
// failed for want of a handler.
|
|
591
|
-
{ queues: this.queues, workerId: this.
|
|
593
|
+
{ queues: this.queues, workerId: this.ownId, leaseMs, names },
|
|
592
594
|
async (claim) => {
|
|
593
595
|
const drawn: { src: ClaimSource; calls: [Registration | undefined, Task[]][] }[] = [];
|
|
594
596
|
let left = free;
|
|
@@ -826,7 +828,7 @@ export class Worker {
|
|
|
826
828
|
try {
|
|
827
829
|
// complete (not succeed): finalizes as canceled if a cancel was requested
|
|
828
830
|
// while the handler ran, else succeeded.
|
|
829
|
-
await this.store.complete({ taskId: ctx.taskId, workerId: this.
|
|
831
|
+
await this.store.complete({ taskId: ctx.taskId, workerId: this.ownId, result });
|
|
830
832
|
ctx.markSettled();
|
|
831
833
|
} catch (err) {
|
|
832
834
|
if (err instanceof LostLease) {
|
|
@@ -967,7 +969,7 @@ export class Worker {
|
|
|
967
969
|
try {
|
|
968
970
|
const renewed = await this.store.heartbeatBatch({
|
|
969
971
|
taskIds: live.map((c) => c.taskId),
|
|
970
|
-
workerId: this.
|
|
972
|
+
workerId: this.ownId,
|
|
971
973
|
leaseMs,
|
|
972
974
|
});
|
|
973
975
|
for (const ctx of live) {
|
|
@@ -1003,7 +1005,7 @@ export class Worker {
|
|
|
1003
1005
|
try {
|
|
1004
1006
|
await this.store.fail({
|
|
1005
1007
|
taskId: ctx.taskId,
|
|
1006
|
-
workerId: this.
|
|
1008
|
+
workerId: this.ownId,
|
|
1007
1009
|
error: envelope,
|
|
1008
1010
|
retryable,
|
|
1009
1011
|
delayMs: failDelayMs(ctx.attempt, retryable, this.backoffMs, this.backoffMaxMs),
|