@c9up/bay 0.1.13 → 0.2.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 +122 -16
- package/dist/BayProvider.d.ts +39 -11
- package/dist/BayProvider.d.ts.map +1 -1
- package/dist/BayProvider.js +35 -13
- package/dist/BayProvider.js.map +1 -1
- package/dist/Job.d.ts +99 -0
- package/dist/Job.d.ts.map +1 -0
- package/dist/Job.js +78 -0
- package/dist/Job.js.map +1 -0
- package/dist/QueueManager.d.ts +140 -21
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/QueueManager.js +247 -53
- package/dist/QueueManager.js.map +1 -1
- package/dist/adapters.d.ts +68 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +56 -0
- package/dist/adapters.js.map +1 -0
- package/dist/augmentations.d.ts +28 -0
- package/dist/augmentations.d.ts.map +1 -0
- package/dist/augmentations.js +17 -0
- package/dist/augmentations.js.map +1 -0
- package/dist/configure.d.ts +1 -0
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +24 -7
- package/dist/configure.js.map +1 -1
- package/dist/console/contract.d.ts +60 -0
- package/dist/console/contract.d.ts.map +1 -0
- package/dist/console/contract.js +36 -0
- package/dist/console/contract.js.map +1 -0
- package/dist/console/index.d.ts +29 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/console/index.js +45 -0
- package/dist/console/index.js.map +1 -0
- package/dist/console/makeJob.d.ts +32 -0
- package/dist/console/makeJob.d.ts.map +1 -0
- package/dist/console/makeJob.js +118 -0
- package/dist/console/makeJob.js.map +1 -0
- package/dist/console/queueWork.d.ts +18 -0
- package/dist/console/queueWork.d.ts.map +1 -0
- package/dist/console/queueWork.js +58 -0
- package/dist/console/queueWork.js.map +1 -0
- package/dist/drivers/MemoryDriver.d.ts +14 -8
- package/dist/drivers/MemoryDriver.d.ts.map +1 -1
- package/dist/drivers/MemoryDriver.js +61 -7
- package/dist/drivers/MemoryDriver.js.map +1 -1
- package/dist/drivers/RedisDriver.d.ts +60 -8
- package/dist/drivers/RedisDriver.d.ts.map +1 -1
- package/dist/drivers/RedisDriver.js +209 -29
- package/dist/drivers/RedisDriver.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +43 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +105 -0
- package/dist/jobs.js.map +1 -0
- package/dist/quasar.d.ts +1 -1
- package/dist/quasar.js +1 -1
- package/dist/testing/FakeQueue.d.ts +15 -9
- package/dist/testing/FakeQueue.d.ts.map +1 -1
- package/dist/testing/FakeQueue.js +13 -3
- package/dist/testing/FakeQueue.js.map +1 -1
- package/package.json +5 -3
- package/src/BayProvider.ts +79 -26
- package/src/Job.ts +137 -0
- package/src/QueueManager.ts +411 -56
- package/src/adapters.ts +75 -0
- package/src/augmentations.ts +31 -0
- package/src/configure.ts +25 -7
- package/src/console/contract.ts +94 -0
- package/src/console/index.ts +68 -0
- package/src/console/makeJob.ts +139 -0
- package/src/console/queueWork.ts +70 -0
- package/src/drivers/MemoryDriver.ts +66 -14
- package/src/drivers/RedisDriver.ts +298 -42
- package/src/index.ts +35 -6
- package/src/jobs.ts +111 -0
- package/src/quasar.ts +1 -1
- package/src/testing/FakeQueue.ts +25 -15
- package/dist/stores.d.ts +0 -41
- package/dist/stores.d.ts.map +0 -1
- package/dist/stores.js +0 -46
- package/dist/stores.js.map +0 -1
- package/src/stores.ts +0 -59
package/src/testing/FakeQueue.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* the fake into a runtime build.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
12
|
+
import type { JobRecord, QueueDriver } from "../QueueManager.js";
|
|
13
13
|
|
|
14
14
|
export interface FakeQueuePredicate {
|
|
15
15
|
/** Custom payload predicate — receives the job's `payload` and
|
|
@@ -23,12 +23,12 @@ export interface FakeQueuePredicate {
|
|
|
23
23
|
|
|
24
24
|
export type FakeQueuePredicateArg =
|
|
25
25
|
| FakeQueuePredicate
|
|
26
|
-
| ((job:
|
|
26
|
+
| ((job: JobRecord) => boolean);
|
|
27
27
|
|
|
28
28
|
export class FakeQueue implements QueueDriver {
|
|
29
|
-
#pushed:
|
|
29
|
+
#pushed: JobRecord[] = [];
|
|
30
30
|
|
|
31
|
-
async push(job:
|
|
31
|
+
async push(job: JobRecord): Promise<void> {
|
|
32
32
|
// Reject duplicate ids to surface the most common test-fixture
|
|
33
33
|
// mistake — two `makeJob({ id: 'x' })` reused across pushes
|
|
34
34
|
// silently corrupts later `fail`/`complete`/`retry` lookups.
|
|
@@ -43,25 +43,35 @@ export class FakeQueue implements QueueDriver {
|
|
|
43
43
|
/** Always returns `null` — fake queues never auto-dispatch.
|
|
44
44
|
* Tests that need handler execution should use the memory
|
|
45
45
|
* driver directly. */
|
|
46
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Always empty: this fake captures what was dispatched, it does not run it.
|
|
48
|
+
*
|
|
49
|
+
* The parameter is declared so the queue names a caller asks for are part of
|
|
50
|
+
* the signature a test reads, even though nothing here serves them.
|
|
51
|
+
*/
|
|
52
|
+
async pop(_queues?: readonly string[]): Promise<JobRecord | null> {
|
|
47
53
|
return null;
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
async fail(job:
|
|
56
|
+
async fail(job: JobRecord, error: string): Promise<void> {
|
|
51
57
|
const found = this.#requireJob(job, "fail");
|
|
52
58
|
found.status = "failed";
|
|
53
59
|
found.error = error;
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
async complete(job:
|
|
62
|
+
async complete(job: JobRecord): Promise<void> {
|
|
57
63
|
const found = this.#requireJob(job, "complete");
|
|
58
64
|
found.status = "completed";
|
|
59
65
|
found.processedAt = Date.now();
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
async retry(job:
|
|
68
|
+
async retry(job: JobRecord): Promise<void> {
|
|
63
69
|
const found = this.#requireJob(job, "retry");
|
|
64
|
-
|
|
70
|
+
// `attempts` is the WORKER's counter, not the driver's: `processOne`
|
|
71
|
+
// increments it before it calls this, and neither real driver touches it
|
|
72
|
+
// again. Incrementing here counted the same attempt twice, so a fake
|
|
73
|
+
// exhausted `maxAttempts` in half the tries the real queue takes — a
|
|
74
|
+
// test double that disagrees with what it stands in for.
|
|
65
75
|
found.status = "pending";
|
|
66
76
|
// Reset transient state from the prior failure so a retried
|
|
67
77
|
// job's invariants match a fresh push (a real driver would
|
|
@@ -73,9 +83,9 @@ export class FakeQueue implements QueueDriver {
|
|
|
73
83
|
|
|
74
84
|
/** Look up the captured copy of a job by id. Throws when the id
|
|
75
85
|
* isn't present — silent no-op on a missing job is the most
|
|
76
|
-
* insidious test bug (caller's local
|
|
86
|
+
* insidious test bug (caller's local job ref shows the new
|
|
77
87
|
* status while the FakeQueue's internal capture is unchanged). */
|
|
78
|
-
#requireJob(job:
|
|
88
|
+
#requireJob(job: JobRecord, verb: string): JobRecord {
|
|
79
89
|
const found = this.#pushed.find((j) => j.id === job.id);
|
|
80
90
|
if (!found) {
|
|
81
91
|
throw new Error(
|
|
@@ -85,7 +95,7 @@ export class FakeQueue implements QueueDriver {
|
|
|
85
95
|
return found;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
async failed(): Promise<
|
|
98
|
+
async failed(): Promise<JobRecord[]> {
|
|
89
99
|
return this.#pushed
|
|
90
100
|
.filter((j) => j.status === "failed")
|
|
91
101
|
.map((j) => ({ ...j }));
|
|
@@ -100,7 +110,7 @@ export class FakeQueue implements QueueDriver {
|
|
|
100
110
|
* shallow clone so test-side mutations can't bleed back into the
|
|
101
111
|
* internal capture store — avoids cross-test contamination.
|
|
102
112
|
*/
|
|
103
|
-
getPushed():
|
|
113
|
+
getPushed(): JobRecord[] {
|
|
104
114
|
return this.#pushed.map((j) => ({ ...j }));
|
|
105
115
|
}
|
|
106
116
|
|
|
@@ -129,7 +139,7 @@ export class FakeQueue implements QueueDriver {
|
|
|
129
139
|
function makeMatcher(
|
|
130
140
|
name: string,
|
|
131
141
|
predicate: FakeQueuePredicateArg | undefined,
|
|
132
|
-
): (j:
|
|
142
|
+
): (j: JobRecord) => boolean {
|
|
133
143
|
// Function-form predicate — caller does ALL the matching, the
|
|
134
144
|
// `name` arg is still a hard prerequisite.
|
|
135
145
|
if (typeof predicate === "function") {
|
|
@@ -162,7 +172,7 @@ function describePredicate(
|
|
|
162
172
|
return `, ${JSON.stringify(predicate)}`;
|
|
163
173
|
}
|
|
164
174
|
|
|
165
|
-
function describeCaptured(captured:
|
|
175
|
+
function describeCaptured(captured: JobRecord[]): string {
|
|
166
176
|
if (captured.length === 0) return "Captured: (none)";
|
|
167
177
|
const lines = captured.map(
|
|
168
178
|
(j, i) =>
|
package/dist/stores.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The queue store factories a config file names — `{ default, stores }`.
|
|
3
|
-
*
|
|
4
|
-
* The shape AdonisJS gives a package with several backends and one selected:
|
|
5
|
-
* a `stores` namespace imported beside `defineConfig`, each entry that
|
|
6
|
-
* namespace's result, and the selection read from the environment. Bay had a
|
|
7
|
-
* single `driver: "memory"` and told everyone else to build the manager by
|
|
8
|
-
* hand, which meant Redis could not be reached from a config file at all.
|
|
9
|
-
*
|
|
10
|
-
* import { defineConfig, stores } from '@c9up/bay'
|
|
11
|
-
*
|
|
12
|
-
* export default defineConfig({
|
|
13
|
-
* default: env.get('QUEUE_STORE'),
|
|
14
|
-
* stores: {
|
|
15
|
-
* memory: stores.memory(),
|
|
16
|
-
* redis: stores.redis({ connection: 'main' }),
|
|
17
|
-
* },
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* Factories are lazy: only the store an application actually uses is built, so
|
|
21
|
-
* naming a Redis queue in a config that runs in memory opens no connection.
|
|
22
|
-
*/
|
|
23
|
-
import type { RedisClientSource } from "./drivers/RedisDriver.js";
|
|
24
|
-
import type { QueueDriver } from "./QueueManager.js";
|
|
25
|
-
/** A driver, built on first use. */
|
|
26
|
-
export type QueueStoreFactory = () => QueueDriver;
|
|
27
|
-
export declare const stores: {
|
|
28
|
-
/** In memory. Jobs do not survive a restart — for tests and dev. */
|
|
29
|
-
memory(): QueueStoreFactory;
|
|
30
|
-
/**
|
|
31
|
-
* Redis. `connection` takes an ioredis-shaped client, a function answering
|
|
32
|
-
* one, or the NAME of a `@c9up/quasar` connection — the last resolved at
|
|
33
|
-
* first use, without bay importing quasar, which stays an optional peer.
|
|
34
|
-
*/
|
|
35
|
-
redis(options: {
|
|
36
|
-
connection: RedisClientSource | string;
|
|
37
|
-
prefix?: string;
|
|
38
|
-
visibilityTimeoutMs?: number;
|
|
39
|
-
}): QueueStoreFactory;
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=stores.d.ts.map
|
package/dist/stores.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC;AAElD,eAAO,MAAM,MAAM;IAClB,oEAAoE;cAC1D,iBAAiB;IAI3B;;;;OAIG;mBACY;QACd,UAAU,EAAE,iBAAiB,GAAG,MAAM,CAAC;QACvC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC7B,GAAG,iBAAiB;CAWrB,CAAC"}
|
package/dist/stores.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The queue store factories a config file names — `{ default, stores }`.
|
|
3
|
-
*
|
|
4
|
-
* The shape AdonisJS gives a package with several backends and one selected:
|
|
5
|
-
* a `stores` namespace imported beside `defineConfig`, each entry that
|
|
6
|
-
* namespace's result, and the selection read from the environment. Bay had a
|
|
7
|
-
* single `driver: "memory"` and told everyone else to build the manager by
|
|
8
|
-
* hand, which meant Redis could not be reached from a config file at all.
|
|
9
|
-
*
|
|
10
|
-
* import { defineConfig, stores } from '@c9up/bay'
|
|
11
|
-
*
|
|
12
|
-
* export default defineConfig({
|
|
13
|
-
* default: env.get('QUEUE_STORE'),
|
|
14
|
-
* stores: {
|
|
15
|
-
* memory: stores.memory(),
|
|
16
|
-
* redis: stores.redis({ connection: 'main' }),
|
|
17
|
-
* },
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* Factories are lazy: only the store an application actually uses is built, so
|
|
21
|
-
* naming a Redis queue in a config that runs in memory opens no connection.
|
|
22
|
-
*/
|
|
23
|
-
import { MemoryDriver } from "./drivers/MemoryDriver.js";
|
|
24
|
-
import { RedisDriver } from "./drivers/RedisDriver.js";
|
|
25
|
-
import { quasarConnection } from "./quasar.js";
|
|
26
|
-
export const stores = {
|
|
27
|
-
/** In memory. Jobs do not survive a restart — for tests and dev. */
|
|
28
|
-
memory() {
|
|
29
|
-
return () => new MemoryDriver();
|
|
30
|
-
},
|
|
31
|
-
/**
|
|
32
|
-
* Redis. `connection` takes an ioredis-shaped client, a function answering
|
|
33
|
-
* one, or the NAME of a `@c9up/quasar` connection — the last resolved at
|
|
34
|
-
* first use, without bay importing quasar, which stays an optional peer.
|
|
35
|
-
*/
|
|
36
|
-
redis(options) {
|
|
37
|
-
const source = typeof options.connection === "string"
|
|
38
|
-
? quasarConnection(options.connection)
|
|
39
|
-
: options.connection;
|
|
40
|
-
return () => new RedisDriver(source, {
|
|
41
|
-
prefix: options.prefix,
|
|
42
|
-
visibilityTimeoutMs: options.visibilityTimeoutMs,
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=stores.js.map
|
package/dist/stores.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stores.js","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK/C,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,oEAAoE;IACpE,MAAM;QACL,OAAO,GAAG,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAIL;QACA,MAAM,MAAM,GACX,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ;YACrC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC;YACtC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;QACvB,OAAO,GAAG,EAAE,CACX,IAAI,WAAW,CAAC,MAAM,EAAE;YACvB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;SAChD,CAAC,CAAC;IACL,CAAC;CACD,CAAC"}
|
package/src/stores.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The queue store factories a config file names — `{ default, stores }`.
|
|
3
|
-
*
|
|
4
|
-
* The shape AdonisJS gives a package with several backends and one selected:
|
|
5
|
-
* a `stores` namespace imported beside `defineConfig`, each entry that
|
|
6
|
-
* namespace's result, and the selection read from the environment. Bay had a
|
|
7
|
-
* single `driver: "memory"` and told everyone else to build the manager by
|
|
8
|
-
* hand, which meant Redis could not be reached from a config file at all.
|
|
9
|
-
*
|
|
10
|
-
* import { defineConfig, stores } from '@c9up/bay'
|
|
11
|
-
*
|
|
12
|
-
* export default defineConfig({
|
|
13
|
-
* default: env.get('QUEUE_STORE'),
|
|
14
|
-
* stores: {
|
|
15
|
-
* memory: stores.memory(),
|
|
16
|
-
* redis: stores.redis({ connection: 'main' }),
|
|
17
|
-
* },
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* Factories are lazy: only the store an application actually uses is built, so
|
|
21
|
-
* naming a Redis queue in a config that runs in memory opens no connection.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { MemoryDriver } from "./drivers/MemoryDriver.js";
|
|
25
|
-
import type { RedisClientSource } from "./drivers/RedisDriver.js";
|
|
26
|
-
import { RedisDriver } from "./drivers/RedisDriver.js";
|
|
27
|
-
import type { QueueDriver } from "./QueueManager.js";
|
|
28
|
-
import { quasarConnection } from "./quasar.js";
|
|
29
|
-
|
|
30
|
-
/** A driver, built on first use. */
|
|
31
|
-
export type QueueStoreFactory = () => QueueDriver;
|
|
32
|
-
|
|
33
|
-
export const stores = {
|
|
34
|
-
/** In memory. Jobs do not survive a restart — for tests and dev. */
|
|
35
|
-
memory(): QueueStoreFactory {
|
|
36
|
-
return () => new MemoryDriver();
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Redis. `connection` takes an ioredis-shaped client, a function answering
|
|
41
|
-
* one, or the NAME of a `@c9up/quasar` connection — the last resolved at
|
|
42
|
-
* first use, without bay importing quasar, which stays an optional peer.
|
|
43
|
-
*/
|
|
44
|
-
redis(options: {
|
|
45
|
-
connection: RedisClientSource | string;
|
|
46
|
-
prefix?: string;
|
|
47
|
-
visibilityTimeoutMs?: number;
|
|
48
|
-
}): QueueStoreFactory {
|
|
49
|
-
const source: RedisClientSource =
|
|
50
|
-
typeof options.connection === "string"
|
|
51
|
-
? quasarConnection(options.connection)
|
|
52
|
-
: options.connection;
|
|
53
|
-
return () =>
|
|
54
|
-
new RedisDriver(source, {
|
|
55
|
-
prefix: options.prefix,
|
|
56
|
-
visibilityTimeoutMs: options.visibilityTimeoutMs,
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
};
|