@arkstack/queue 0.19.1 → 0.19.3
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
CHANGED
|
@@ -18,7 +18,7 @@ Queue module for Arkstack, providing a driver based queue transport and worker f
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
// src/config/queue.ts
|
|
21
|
-
import type { QueueConfig } from '@arkstack/queue'
|
|
21
|
+
import type { QueueConfig } from '@arkstack/queue'
|
|
22
22
|
|
|
23
23
|
export default (): QueueConfig => ({
|
|
24
24
|
default: env('QUEUE_CONNECTION', 'sync'),
|
|
@@ -31,19 +31,19 @@ export default (): QueueConfig => ({
|
|
|
31
31
|
port: env('REDIS_PORT', 6379),
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
-
})
|
|
34
|
+
})
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## Usage
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
|
-
import { Queue } from '@arkstack/queue'
|
|
40
|
+
import { Queue } from '@arkstack/queue'
|
|
41
41
|
|
|
42
|
-
await Queue.push(new SendWelcomeEmail(user))
|
|
43
|
-
await Queue.later(60, new ChargeInvoice(invoiceId))
|
|
44
|
-
await Queue.connection('redis').push(job, 'emails')
|
|
45
|
-
await Queue.size('emails')
|
|
46
|
-
await Queue.clear('emails')
|
|
42
|
+
await Queue.push(new SendWelcomeEmail(user)) // onto the default connection
|
|
43
|
+
await Queue.later(60, new ChargeInvoice(invoiceId)) // after 60 seconds
|
|
44
|
+
await Queue.connection('redis').push(job, 'emails') // a specific connection/queue
|
|
45
|
+
await Queue.size('emails')
|
|
46
|
+
await Queue.clear('emails')
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Workers
|
|
@@ -58,10 +58,10 @@ ark queue:clear redis --queue=emails
|
|
|
58
58
|
Programmatically:
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import { Queue } from '@arkstack/queue'
|
|
61
|
+
import { Queue } from '@arkstack/queue'
|
|
62
62
|
|
|
63
|
-
const worker = Queue.worker('database')
|
|
64
|
-
await worker.daemon({ queue: 'default', sleep: 3 })
|
|
63
|
+
const worker = Queue.worker('database')
|
|
64
|
+
await worker.daemon({ queue: 'default', sleep: 3 })
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
A job is **deleted** on success, **released** for another attempt on failure, and **marked failed** (invoking its `failed` hook) once it exhausts `tries`.
|
|
@@ -73,10 +73,8 @@ instances in the worker. `@arkstack/jobs` registers these strategies for you; to
|
|
|
73
73
|
do it manually:
|
|
74
74
|
|
|
75
75
|
```ts
|
|
76
|
-
import { Queue } from '@arkstack/queue'
|
|
76
|
+
import { Queue } from '@arkstack/queue'
|
|
77
77
|
|
|
78
|
-
Queue.serializeUsing((job) => ({
|
|
79
|
-
|
|
80
|
-
}));
|
|
81
|
-
Queue.resolveJobsUsing((payload) => rebuildJob(payload));
|
|
78
|
+
Queue.serializeUsing((job) => ({/* JobPayload */}))
|
|
79
|
+
Queue.resolveJobsUsing((payload) => rebuildJob(payload))
|
|
82
80
|
```
|
|
@@ -66,52 +66,52 @@ var Job = class {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* The unique job id.
|
|
69
|
-
*
|
|
70
|
-
* @returns
|
|
69
|
+
*
|
|
70
|
+
* @returns
|
|
71
71
|
*/
|
|
72
72
|
id() {
|
|
73
73
|
return this.payload.id;
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* The job's display name (used to resolve the job class).
|
|
75
|
+
/**
|
|
76
|
+
* The job's display name (used to resolve the job class).
|
|
77
77
|
*/
|
|
78
78
|
name() {
|
|
79
79
|
return this.payload.displayName;
|
|
80
80
|
}
|
|
81
|
-
/**
|
|
82
|
-
* How many times this job has been attempted (including the current run).
|
|
81
|
+
/**
|
|
82
|
+
* How many times this job has been attempted (including the current run).
|
|
83
83
|
*/
|
|
84
84
|
attempts() {
|
|
85
85
|
return this.payload.attempts;
|
|
86
86
|
}
|
|
87
|
-
/**
|
|
88
|
-
* The maximum number of attempts, or `null` for unlimited.
|
|
87
|
+
/**
|
|
88
|
+
* The maximum number of attempts, or `null` for unlimited.
|
|
89
89
|
*/
|
|
90
90
|
maxTries() {
|
|
91
91
|
return this.payload.maxTries;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Seconds to wait before a released job becomes available again.
|
|
94
|
+
* Seconds to wait before a released job becomes available again.
|
|
95
95
|
*/
|
|
96
96
|
backoff() {
|
|
97
97
|
return this.payload.backoff;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Acknowledge the job as done and remove it from the queue.
|
|
100
|
+
* Acknowledge the job as done and remove it from the queue.
|
|
101
101
|
*/
|
|
102
102
|
async delete() {
|
|
103
103
|
this.deleted = true;
|
|
104
104
|
await this.handlers.delete();
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* Release the job back onto the queue, optionally after a delay.
|
|
107
|
+
* Release the job back onto the queue, optionally after a delay.
|
|
108
108
|
*/
|
|
109
109
|
async release(delay = 0) {
|
|
110
110
|
this.released = true;
|
|
111
111
|
await this.handlers.release(delay);
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
* Mark the job as having failed permanently.
|
|
114
|
+
* Mark the job as having failed permanently.
|
|
115
115
|
*/
|
|
116
116
|
markAsFailed() {
|
|
117
117
|
this.failed = true;
|
|
@@ -246,10 +246,10 @@ var DatabaseQueue = class extends QueueContract {
|
|
|
246
246
|
/**
|
|
247
247
|
* Due, unreserved jobs on the given queue, oldest first. Released jobs become
|
|
248
248
|
* unreserved with a future `available_at`, so they naturally wait their turn.
|
|
249
|
-
*
|
|
250
|
-
* @param db
|
|
251
|
-
* @param queue
|
|
252
|
-
* @returns
|
|
249
|
+
*
|
|
250
|
+
* @param db
|
|
251
|
+
* @param queue
|
|
252
|
+
* @returns
|
|
253
253
|
*/
|
|
254
254
|
availableQuery(db, queue) {
|
|
255
255
|
return db.table(this.options.table).where({ queue }).whereNull("reserved_at").whereRaw("available_at <= " + now$1());
|
|
@@ -405,8 +405,8 @@ var SyncQueue = class extends QueueContract {
|
|
|
405
405
|
/**
|
|
406
406
|
* Run a job, invoking its `failed` hook and rethrowing on error so the
|
|
407
407
|
* caller (e.g. a dispatch) observes the failure synchronously.
|
|
408
|
-
*
|
|
409
|
-
* @param job
|
|
408
|
+
*
|
|
409
|
+
* @param job
|
|
410
410
|
*/
|
|
411
411
|
async execute(job) {
|
|
412
412
|
try {
|
|
@@ -542,9 +542,9 @@ var Queue = class {
|
|
|
542
542
|
static customDrivers = {};
|
|
543
543
|
/**
|
|
544
544
|
* Resolve a queue connection by name (or the default when omitted).
|
|
545
|
-
*
|
|
546
|
-
* @param name
|
|
547
|
-
* @returns
|
|
545
|
+
*
|
|
546
|
+
* @param name
|
|
547
|
+
* @returns
|
|
548
548
|
*/
|
|
549
549
|
static connection(name) {
|
|
550
550
|
const key = name ?? configure("default", "sync");
|
|
@@ -553,9 +553,9 @@ var Queue = class {
|
|
|
553
553
|
}
|
|
554
554
|
/**
|
|
555
555
|
* Register a custom connection driver factory.
|
|
556
|
-
*
|
|
557
|
-
* @param name
|
|
558
|
-
* @returns
|
|
556
|
+
*
|
|
557
|
+
* @param name
|
|
558
|
+
* @returns
|
|
559
559
|
*/
|
|
560
560
|
static extend(driver, factory) {
|
|
561
561
|
this.customDrivers[driver] = factory;
|
|
@@ -563,9 +563,9 @@ var Queue = class {
|
|
|
563
563
|
}
|
|
564
564
|
/**
|
|
565
565
|
* Register how jobs are reconstructed from a payload (used by workers).
|
|
566
|
-
*
|
|
567
|
-
* @param name
|
|
568
|
-
* @returns
|
|
566
|
+
*
|
|
567
|
+
* @param name
|
|
568
|
+
* @returns
|
|
569
569
|
*/
|
|
570
570
|
static resolveJobsUsing(resolver) {
|
|
571
571
|
setResolver(resolver);
|
|
@@ -573,9 +573,9 @@ var Queue = class {
|
|
|
573
573
|
}
|
|
574
574
|
/**
|
|
575
575
|
* Register how job instances are serialized for storage.
|
|
576
|
-
*
|
|
577
|
-
* @param serializer
|
|
578
|
-
* @returns
|
|
576
|
+
*
|
|
577
|
+
* @param serializer
|
|
578
|
+
* @returns
|
|
579
579
|
*/
|
|
580
580
|
static serializeUsing(serializer) {
|
|
581
581
|
setSerializer(serializer);
|
|
@@ -583,18 +583,18 @@ var Queue = class {
|
|
|
583
583
|
}
|
|
584
584
|
/**
|
|
585
585
|
* Clear memoized connections. Intended for tests or runtime reconfiguration.
|
|
586
|
-
*
|
|
587
|
-
* @param serializer
|
|
588
|
-
* @returns
|
|
586
|
+
*
|
|
587
|
+
* @param serializer
|
|
588
|
+
* @returns
|
|
589
589
|
*/
|
|
590
590
|
static clearResolved() {
|
|
591
591
|
this.connections = {};
|
|
592
592
|
}
|
|
593
593
|
/**
|
|
594
594
|
* Create a worker bound to the given (or default) connection.
|
|
595
|
-
*
|
|
596
|
-
* @param serializer
|
|
597
|
-
* @returns
|
|
595
|
+
*
|
|
596
|
+
* @param serializer
|
|
597
|
+
* @returns
|
|
598
598
|
*/
|
|
599
599
|
static worker(name) {
|
|
600
600
|
return new Worker(this.connection(name));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as Worker, t as Queue } from "../QueueManager
|
|
1
|
+
import { r as Worker, t as Queue } from "../QueueManager--4wZ8gJz.js";
|
|
2
2
|
import { Command } from "@h3ravel/musket";
|
|
3
3
|
import { bootArkorm } from "@arkstack/database";
|
|
4
4
|
//#region src/commands/QueueWorkCommand.ts
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RedisQueue, c as Job, d as serializeJob, f as setResolver, i as SyncQueue, l as resetSerialization, n as configure, o as DatabaseQueue, p as setSerializer, r as Worker, s as QueueContract, t as Queue, u as resolveJob } from "./QueueManager
|
|
1
|
+
import { a as RedisQueue, c as Job, d as serializeJob, f as setResolver, i as SyncQueue, l as resetSerialization, n as configure, o as DatabaseQueue, p as setSerializer, r as Worker, s as QueueContract, t as Queue, u as resolveJob } from "./QueueManager--4wZ8gJz.js";
|
|
2
2
|
export { DatabaseQueue, Job, Queue, QueueContract, RedisQueue, SyncQueue, Worker, configure, resetSerialization, resolveJob, serializeJob, setResolver, setSerializer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/queue",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Queue module for Arkstack, providing a driver based queue transport and worker for background processing.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net/guide/queue",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"./package.json": "./package.json"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@arkstack/common": "^0.19.
|
|
37
|
+
"@arkstack/common": "^0.19.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@h3ravel/musket": "^2.2.13",
|
|
41
41
|
"ioredis": "^5.4.1",
|
|
42
|
-
"@arkstack/contract": "^0.19.
|
|
43
|
-
"@arkstack/database": "^0.19.
|
|
42
|
+
"@arkstack/contract": "^0.19.3",
|
|
43
|
+
"@arkstack/database": "^0.19.3"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"@arkstack/database": {
|