@warlock.js/queue 5.13.0 → 5.15.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/CHANGELOG.md +27 -0
- package/README.md +43 -7
- package/cjs/index.cjs +525 -29
- package/cjs/index.cjs.map +1 -1
- package/esm/dashboard-boot.d.mts +20 -0
- package/esm/dashboard-boot.d.mts.map +1 -0
- package/esm/dashboard-boot.mjs +38 -0
- package/esm/dashboard-boot.mjs.map +1 -0
- package/esm/dashboard-guard-plugin.mjs +28 -0
- package/esm/dashboard-guard-plugin.mjs.map +1 -0
- package/esm/dashboard-middleware-adapter.mjs +39 -0
- package/esm/dashboard-middleware-adapter.mjs.map +1 -0
- package/esm/dashboard.d.mts +8 -0
- package/esm/dashboard.d.mts.map +1 -1
- package/esm/dashboard.mjs +3 -1
- package/esm/dashboard.mjs.map +1 -1
- package/esm/define-job.mjs +13 -6
- package/esm/define-job.mjs.map +1 -1
- package/esm/index.d.mts +4 -2
- package/esm/index.mjs +3 -1
- package/esm/queue-connector.d.mts.map +1 -1
- package/esm/queue-connector.mjs +17 -1
- package/esm/queue-connector.mjs.map +1 -1
- package/esm/queue-dashboard-unguarded.error.d.mts +13 -0
- package/esm/queue-dashboard-unguarded.error.d.mts.map +1 -0
- package/esm/queue-dashboard-unguarded.error.mjs +17 -0
- package/esm/queue-dashboard-unguarded.error.mjs.map +1 -0
- package/esm/types.d.mts +19 -2
- package/esm/types.d.mts.map +1 -1
- package/llms-full.txt +45 -9
- package/llms.txt +2 -2
- package/package.json +3 -17
- package/skills/configure-queue/SKILL.md +4 -0
- package/skills/manage-failed-jobs/SKILL.md +33 -4
- package/skills/overview/SKILL.md +1 -1
- package/skills/queue-notifications/SKILL.md +6 -4
- package/cjs/define-job-DideGKQK.cjs +0 -468
- package/cjs/define-job-DideGKQK.cjs.map +0 -1
- package/cjs/notifications/index.cjs +0 -68
- package/cjs/notifications/index.cjs.map +0 -1
- package/esm/notifications/index.d.mts +0 -2
- package/esm/notifications/index.mjs +0 -3
- package/esm/notifications/queue-notification-dispatcher.d.mts +0 -34
- package/esm/notifications/queue-notification-dispatcher.d.mts.map +0 -1
- package/esm/notifications/queue-notification-dispatcher.mjs +0 -67
- package/esm/notifications/queue-notification-dispatcher.mjs.map +0 -1
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { toMilliseconds } from "../duration.mjs";
|
|
2
|
-
import { defineJob } from "../define-job.mjs";
|
|
3
|
-
import { UnrecoverableError } from "bullmq";
|
|
4
|
-
import { getNotificationConfig } from "@warlock.js/notifications";
|
|
5
|
-
|
|
6
|
-
//#region ../queue/src/notifications/queue-notification-dispatcher.ts
|
|
7
|
-
/**
|
|
8
|
-
* BullMQ-backed `QueueDispatcher` for `@warlock.js/notifications`.
|
|
9
|
-
*
|
|
10
|
-
* Notifications renders the payload and resolves the route BEFORE handing a
|
|
11
|
-
* job to its dispatcher, so the job (`{ channel, route, payload, options }`)
|
|
12
|
-
* is plain JSON. This adapter enqueues it as a queue job; the job's handler,
|
|
13
|
-
* running in any worker process, looks the channel up by name in that
|
|
14
|
-
* process's notifications config and calls `channel.send`.
|
|
15
|
-
*
|
|
16
|
-
* Notifications itself has no dependency on this package.
|
|
17
|
-
*/
|
|
18
|
-
/** The job name notification deliveries run under. */
|
|
19
|
-
const NOTIFICATION_JOB_NAME = "warlock.notifications.deliver";
|
|
20
|
-
/**
|
|
21
|
-
* Create the dispatcher for `NotificationConfig.queue`.
|
|
22
|
-
*
|
|
23
|
-
* - `SendOptions.delay` is honoured: a number is SECONDS (notifications'
|
|
24
|
-
* convention), a string is a duration such as `"10m"`.
|
|
25
|
-
* - A failing `channel.send` throws, so the delivery is retried per
|
|
26
|
-
* `attempts` / `backoff` and ends in `failedJobs()` when exhausted.
|
|
27
|
-
* - A channel missing from the worker's notifications config fails at once,
|
|
28
|
-
* without retries.
|
|
29
|
-
*
|
|
30
|
-
* @example src/config/notifications.ts
|
|
31
|
-
* import { queueNotificationDispatcher } from "@warlock.js/queue/notifications";
|
|
32
|
-
*
|
|
33
|
-
* const config: NotificationConfig = {
|
|
34
|
-
* channels: { mail: mailChannel() },
|
|
35
|
-
* queue: queueNotificationDispatcher({ attempts: 3, backoff: { type: "exponential", delay: 5000 } }),
|
|
36
|
-
* };
|
|
37
|
-
*/
|
|
38
|
-
function queueNotificationDispatcher(options = {}) {
|
|
39
|
-
const deliver = defineNotificationJob(options);
|
|
40
|
-
return { async dispatch(job) {
|
|
41
|
-
await deliver.dispatch(job, { delay: job.options.delay === void 0 ? void 0 : notificationDelay(job.options.delay) });
|
|
42
|
-
} };
|
|
43
|
-
}
|
|
44
|
-
function defineNotificationJob(options) {
|
|
45
|
-
return defineJob({
|
|
46
|
-
name: NOTIFICATION_JOB_NAME,
|
|
47
|
-
queue: options.queue,
|
|
48
|
-
attempts: options.attempts,
|
|
49
|
-
backoff: options.backoff,
|
|
50
|
-
async handle(job) {
|
|
51
|
-
const channel = getNotificationConfig().channels[job.channel];
|
|
52
|
-
if (!channel) throw new UnrecoverableError(`Notification channel "${job.channel}" is not configured in this worker's notifications config.`);
|
|
53
|
-
await channel.send({
|
|
54
|
-
payload: job.payload,
|
|
55
|
-
route: job.route,
|
|
56
|
-
options: job.options
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function notificationDelay(delay) {
|
|
62
|
-
return typeof delay === "number" ? delay * 1e3 : toMilliseconds(delay);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { NOTIFICATION_JOB_NAME, queueNotificationDispatcher };
|
|
67
|
-
//# sourceMappingURL=queue-notification-dispatcher.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queue-notification-dispatcher.mjs","names":[],"sources":["../../../../../../../queue/src/notifications/queue-notification-dispatcher.ts"],"sourcesContent":["/**\n * BullMQ-backed `QueueDispatcher` for `@warlock.js/notifications`.\n *\n * Notifications renders the payload and resolves the route BEFORE handing a\n * job to its dispatcher, so the job (`{ channel, route, payload, options }`)\n * is plain JSON. This adapter enqueues it as a queue job; the job's handler,\n * running in any worker process, looks the channel up by name in that\n * process's notifications config and calls `channel.send`.\n *\n * Notifications itself has no dependency on this package.\n */\nimport { getNotificationConfig, type QueueDispatcher } from \"@warlock.js/notifications\";\nimport { UnrecoverableError } from \"bullmq\";\nimport { defineJob } from \"../define-job\";\nimport { toMilliseconds } from \"../duration\";\nimport type { Duration, JobBackoff, QueueJob } from \"../types\";\n\n/** The job name notification deliveries run under. */\nexport const NOTIFICATION_JOB_NAME = \"warlock.notifications.deliver\";\n\nexport type NotificationJobPayload = Parameters<QueueDispatcher[\"dispatch\"]>[0];\n\nexport type QueueNotificationDispatcherOptions = {\n /** Queue to deliver on. Default: the default queue. */\n queue?: string;\n /** Attempts per delivery. Default: `queue.defaultJobOptions.attempts`, else `1`. */\n attempts?: number;\n /** Backoff between attempts. */\n backoff?: JobBackoff;\n};\n\n/**\n * Create the dispatcher for `NotificationConfig.queue`.\n *\n * - `SendOptions.delay` is honoured: a number is SECONDS (notifications'\n * convention), a string is a duration such as `\"10m\"`.\n * - A failing `channel.send` throws, so the delivery is retried per\n * `attempts` / `backoff` and ends in `failedJobs()` when exhausted.\n * - A channel missing from the worker's notifications config fails at once,\n * without retries.\n *\n * @example src/config/notifications.ts\n * import { queueNotificationDispatcher } from \"@warlock.js/queue/notifications\";\n *\n * const config: NotificationConfig = {\n * channels: { mail: mailChannel() },\n * queue: queueNotificationDispatcher({ attempts: 3, backoff: { type: \"exponential\", delay: 5000 } }),\n * };\n */\nexport function queueNotificationDispatcher(\n options: QueueNotificationDispatcherOptions = {},\n): QueueDispatcher {\n const deliver = defineNotificationJob(options);\n\n return {\n async dispatch(job) {\n await deliver.dispatch(job, {\n delay: job.options.delay === undefined ? undefined : notificationDelay(job.options.delay),\n });\n },\n };\n}\n\nfunction defineNotificationJob(\n options: QueueNotificationDispatcherOptions,\n): QueueJob<NotificationJobPayload, void> {\n return defineJob<NotificationJobPayload, void>({\n name: NOTIFICATION_JOB_NAME,\n queue: options.queue,\n attempts: options.attempts,\n backoff: options.backoff,\n async handle(job) {\n const channels = getNotificationConfig().channels as Record<\n string,\n { send(context: never): Promise<void> } | undefined\n >;\n const channel = channels[job.channel];\n\n if (!channel) {\n throw new UnrecoverableError(\n `Notification channel \"${job.channel}\" is not configured in this worker's notifications config.`,\n );\n }\n\n await channel.send({ payload: job.payload, route: job.route, options: job.options } as never);\n },\n });\n}\n\nfunction notificationDelay(delay: number | string): Duration {\n return typeof delay === \"number\" ? delay * 1_000 : toMilliseconds(delay);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAa,wBAAwB;;;;;;;;;;;;;;;;;;;AA+BrC,SAAgB,4BACd,UAA8C,CAAC,GAC9B;CACjB,MAAM,UAAU,sBAAsB,OAAO;CAE7C,OAAO,EACL,MAAM,SAAS,KAAK;EAClB,MAAM,QAAQ,SAAS,KAAK,EAC1B,OAAO,IAAI,QAAQ,UAAU,SAAY,SAAY,kBAAkB,IAAI,QAAQ,KAAK,EAC1F,CAAC;CACH,EACF;AACF;AAEA,SAAS,sBACP,SACwC;CACxC,OAAO,UAAwC;EAC7C,MAAM;EACN,OAAO,QAAQ;EACf,UAAU,QAAQ;EAClB,SAAS,QAAQ;EACjB,MAAM,OAAO,KAAK;GAKhB,MAAM,UAJW,sBAAsB,CAAC,CAAC,SAIhB,IAAI;GAE7B,IAAI,CAAC,SACH,MAAM,IAAI,mBACR,yBAAyB,IAAI,QAAQ,2DACvC;GAGF,MAAM,QAAQ,KAAK;IAAE,SAAS,IAAI;IAAS,OAAO,IAAI;IAAO,SAAS,IAAI;GAAQ,CAAU;EAC9F;CACF,CAAC;AACH;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,OAAO,OAAO,UAAU,WAAW,QAAQ,MAAQ,eAAe,KAAK;AACzE"}
|