@contractspec/lib.jobs 1.57.0 → 1.59.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.
Files changed (92) hide show
  1. package/dist/contracts/index.d.ts +494 -500
  2. package/dist/contracts/index.d.ts.map +1 -1
  3. package/dist/contracts/index.js +298 -461
  4. package/dist/entities/index.d.ts +117 -122
  5. package/dist/entities/index.d.ts.map +1 -1
  6. package/dist/entities/index.js +170 -193
  7. package/dist/events.d.ts +297 -303
  8. package/dist/events.d.ts.map +1 -1
  9. package/dist/events.js +199 -351
  10. package/dist/handlers/gmail-sync-handler.d.ts +5 -9
  11. package/dist/handlers/gmail-sync-handler.d.ts.map +1 -1
  12. package/dist/handlers/gmail-sync-handler.js +8 -8
  13. package/dist/handlers/index.d.ts +5 -9
  14. package/dist/handlers/index.d.ts.map +1 -1
  15. package/dist/handlers/index.js +53 -10
  16. package/dist/handlers/ping-job.d.ts +6 -10
  17. package/dist/handlers/ping-job.d.ts.map +1 -1
  18. package/dist/handlers/ping-job.js +13 -12
  19. package/dist/handlers/storage-document-handler.d.ts +7 -11
  20. package/dist/handlers/storage-document-handler.d.ts.map +1 -1
  21. package/dist/handlers/storage-document-handler.js +15 -13
  22. package/dist/index.d.ts +7 -24
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1366 -64
  25. package/dist/jobs.capability.d.ts +2 -7
  26. package/dist/jobs.capability.d.ts.map +1 -1
  27. package/dist/jobs.capability.js +29 -33
  28. package/dist/jobs.feature.d.ts +1 -6
  29. package/dist/jobs.feature.d.ts.map +1 -1
  30. package/dist/jobs.feature.js +45 -108
  31. package/dist/node/contracts/index.js +318 -0
  32. package/dist/node/entities/index.js +174 -0
  33. package/dist/node/events.js +200 -0
  34. package/dist/node/handlers/gmail-sync-handler.js +9 -0
  35. package/dist/node/handlers/index.js +55 -0
  36. package/dist/node/handlers/ping-job.js +14 -0
  37. package/dist/node/handlers/storage-document-handler.js +16 -0
  38. package/dist/node/index.js +1368 -0
  39. package/dist/node/jobs.capability.js +28 -0
  40. package/dist/node/jobs.feature.js +46 -0
  41. package/dist/node/queue/gcp-cloud-tasks.js +66 -0
  42. package/dist/node/queue/gcp-pubsub.js +54 -0
  43. package/dist/node/queue/index.js +478 -0
  44. package/dist/node/queue/memory-queue.js +160 -0
  45. package/dist/node/queue/register-defined-job.js +15 -0
  46. package/dist/node/queue/scaleway-sqs-queue.js +206 -0
  47. package/dist/node/queue/types.js +10 -0
  48. package/dist/node/scheduler/index.js +117 -0
  49. package/dist/queue/gcp-cloud-tasks.d.ts +33 -36
  50. package/dist/queue/gcp-cloud-tasks.d.ts.map +1 -1
  51. package/dist/queue/gcp-cloud-tasks.js +65 -59
  52. package/dist/queue/gcp-pubsub.d.ts +18 -21
  53. package/dist/queue/gcp-pubsub.d.ts.map +1 -1
  54. package/dist/queue/gcp-pubsub.js +53 -45
  55. package/dist/queue/index.d.ts +6 -15
  56. package/dist/queue/index.d.ts.map +1 -1
  57. package/dist/queue/index.js +476 -20
  58. package/dist/queue/memory-queue.d.ts +25 -29
  59. package/dist/queue/memory-queue.d.ts.map +1 -1
  60. package/dist/queue/memory-queue.js +159 -138
  61. package/dist/queue/register-defined-job.d.ts +3 -7
  62. package/dist/queue/register-defined-job.d.ts.map +1 -1
  63. package/dist/queue/register-defined-job.js +14 -14
  64. package/dist/queue/scaleway-sqs-queue.d.ts +31 -35
  65. package/dist/queue/scaleway-sqs-queue.d.ts.map +1 -1
  66. package/dist/queue/scaleway-sqs-queue.js +205 -173
  67. package/dist/queue/types.d.ts +2 -8
  68. package/dist/queue/types.d.ts.map +1 -1
  69. package/dist/queue/types.js +11 -12
  70. package/dist/scheduler/index.d.ts +68 -72
  71. package/dist/scheduler/index.d.ts.map +1 -1
  72. package/dist/scheduler/index.js +113 -141
  73. package/package.json +176 -50
  74. package/dist/_virtual/_rolldown/runtime.js +0 -36
  75. package/dist/contracts/index.js.map +0 -1
  76. package/dist/entities/index.js.map +0 -1
  77. package/dist/events.js.map +0 -1
  78. package/dist/handlers/gmail-sync-handler.js.map +0 -1
  79. package/dist/handlers/index.js.map +0 -1
  80. package/dist/handlers/ping-job.js.map +0 -1
  81. package/dist/handlers/storage-document-handler.js.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/jobs.capability.js.map +0 -1
  84. package/dist/jobs.feature.js.map +0 -1
  85. package/dist/queue/gcp-cloud-tasks.js.map +0 -1
  86. package/dist/queue/gcp-pubsub.js.map +0 -1
  87. package/dist/queue/index.js.map +0 -1
  88. package/dist/queue/memory-queue.js.map +0 -1
  89. package/dist/queue/register-defined-job.js.map +0 -1
  90. package/dist/queue/scaleway-sqs-queue.js.map +0 -1
  91. package/dist/queue/types.js.map +0 -1
  92. package/dist/scheduler/index.js.map +0 -1
@@ -1,175 +1,207 @@
1
- import { types_exports } from "./types.js";
2
- import { randomUUID } from "node:crypto";
3
- import { DeleteMessageCommand, ReceiveMessageCommand, SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
1
+ // @bun
2
+ // src/queue/types.ts
3
+ export * from "@contractspec/lib.contracts/jobs/queue";
4
+ import {
5
+ calculateBackoff,
6
+ DEFAULT_RETRY_POLICY
7
+ } from "@contractspec/lib.contracts/jobs/queue";
4
8
 
5
- //#region src/queue/scaleway-sqs-queue.ts
6
- var ScalewaySqsJobQueue = class {
7
- sqs;
8
- queueUrl;
9
- waitTimeSeconds;
10
- maxNumberOfMessages;
11
- visibilityTimeoutSeconds;
12
- handlers = /* @__PURE__ */ new Map();
13
- logger;
14
- running = false;
15
- constructor(config) {
16
- this.logger = config.logger;
17
- const accessKeyId = config.credentials?.accessKeyId ?? process.env.SCALEWAY_ACCESS_KEY_QUEUE;
18
- const secretAccessKey = config.credentials?.secretAccessKey ?? process.env.SCALEWAY_SECRET_KEY_QUEUE;
19
- if (!accessKeyId || !secretAccessKey) throw new Error("Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env");
20
- this.sqs = new SQSClient({
21
- region: config.region ?? process.env.SCALEWAY_REGION ?? "par",
22
- endpoint: config.endpoint ?? "https://sqs.mnq.fr-par.scaleway.com",
23
- credentials: {
24
- accessKeyId,
25
- secretAccessKey
26
- }
27
- });
28
- this.queueUrl = config.queueUrl;
29
- this.waitTimeSeconds = config.waitTimeSeconds ?? 20;
30
- this.maxNumberOfMessages = config.maxNumberOfMessages ?? 5;
31
- this.visibilityTimeoutSeconds = config.visibilityTimeoutSeconds ?? 60;
32
- }
33
- async enqueue(jobType, payload, options = {}) {
34
- const id = randomUUID();
35
- const now = /* @__PURE__ */ new Date();
36
- const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now;
37
- const envelope = {
38
- id,
39
- type: jobType,
40
- payload
41
- };
42
- await this.sqs.send(new SendMessageCommand({
43
- QueueUrl: this.queueUrl,
44
- MessageBody: JSON.stringify(envelope),
45
- DelaySeconds: options.delaySeconds ?? 0
46
- }));
47
- return {
48
- id,
49
- type: jobType,
50
- version: "1.0.0",
51
- payload,
52
- status: "pending",
53
- priority: options.priority ?? 0,
54
- attempts: 0,
55
- maxRetries: options.maxRetries ?? types_exports.DEFAULT_RETRY_POLICY.maxRetries,
56
- createdAt: now,
57
- updatedAt: now,
58
- scheduledAt,
59
- dedupeKey: options.dedupeKey,
60
- tenantId: options.tenantId,
61
- userId: options.userId,
62
- traceId: options.traceId,
63
- metadata: options.metadata
64
- };
65
- }
66
- register(jobType, handler) {
67
- if (this.handlers.has(jobType)) throw new Error(`Handler already registered for job type "${jobType}"`);
68
- this.handlers.set(jobType, handler);
69
- }
70
- start() {
71
- if (this.running) return;
72
- this.running = true;
73
- this.pollLoop().catch((error) => {
74
- this.logger?.error?.("jobs.queue.scaleway_sqs.poll_loop_fatal", { error: error instanceof Error ? error.message : String(error) });
75
- this.running = false;
76
- });
77
- }
78
- async stop() {
79
- this.running = false;
80
- }
81
- async pollLoop() {
82
- this.logger?.info?.("jobs.queue.scaleway_sqs.started", { queueUrl: this.queueUrl });
83
- while (this.running) try {
84
- const messages = (await this.sqs.send(new ReceiveMessageCommand({
85
- QueueUrl: this.queueUrl,
86
- MaxNumberOfMessages: this.maxNumberOfMessages,
87
- WaitTimeSeconds: this.waitTimeSeconds,
88
- VisibilityTimeout: this.visibilityTimeoutSeconds,
89
- MessageSystemAttributeNames: ["ApproximateReceiveCount"]
90
- }))).Messages ?? [];
91
- if (messages.length === 0) continue;
92
- for (const msg of messages) {
93
- if (!msg.Body || !msg.ReceiptHandle) {
94
- this.logger?.warn?.("jobs.queue.scaleway_sqs.invalid_message", {
95
- messageId: msg.MessageId,
96
- reason: "missing_body_or_receipt"
97
- });
98
- continue;
99
- }
100
- let envelope;
101
- try {
102
- envelope = JSON.parse(msg.Body);
103
- } catch (err) {
104
- this.logger?.warn?.("jobs.queue.scaleway_sqs.parse_failed", {
105
- messageId: msg.MessageId,
106
- error: err instanceof Error ? err.message : String(err)
107
- });
108
- await this.deleteMessage(msg.ReceiptHandle);
109
- continue;
110
- }
111
- const handler = this.handlers.get(envelope.type);
112
- if (!handler) {
113
- this.logger?.warn?.("jobs.queue.scaleway_sqs.missing_handler", {
114
- jobType: envelope.type,
115
- messageId: msg.MessageId
116
- });
117
- await this.deleteMessage(msg.ReceiptHandle);
118
- continue;
119
- }
120
- const now = /* @__PURE__ */ new Date();
121
- const attempts = parseInt(msg.Attributes?.ApproximateReceiveCount ?? "1", 10);
122
- const job = {
123
- id: envelope.id,
124
- type: envelope.type,
125
- version: "1.0.0",
126
- payload: envelope.payload,
127
- status: "pending",
128
- priority: 0,
129
- attempts,
130
- maxRetries: types_exports.DEFAULT_RETRY_POLICY.maxRetries,
131
- createdAt: now,
132
- updatedAt: now
133
- };
134
- job.status = "running";
135
- job.updatedAt = /* @__PURE__ */ new Date();
136
- try {
137
- await handler(job);
138
- job.status = "completed";
139
- job.updatedAt = /* @__PURE__ */ new Date();
140
- await this.deleteMessage(msg.ReceiptHandle);
141
- } catch (err) {
142
- job.status = "failed";
143
- job.lastError = err instanceof Error ? err.message : "Unknown job error";
144
- job.updatedAt = /* @__PURE__ */ new Date();
145
- this.logger?.error?.("jobs.queue.scaleway_sqs.job_failed", {
146
- jobType: job.type,
147
- jobId: job.id,
148
- error: err instanceof Error ? err.message : String(err)
149
- });
150
- }
151
- }
152
- } catch (err) {
153
- this.logger?.error?.("jobs.queue.scaleway_sqs.poll_error", { error: err instanceof Error ? err.message : String(err) });
154
- await this.sleep(5e3);
155
- }
156
- this.logger?.info?.("jobs.queue.scaleway_sqs.stopped", { queueUrl: this.queueUrl });
157
- }
158
- async deleteMessage(receiptHandle) {
159
- try {
160
- await this.sqs.send(new DeleteMessageCommand({
161
- QueueUrl: this.queueUrl,
162
- ReceiptHandle: receiptHandle
163
- }));
164
- } catch (err) {
165
- this.logger?.warn?.("jobs.queue.scaleway_sqs.delete_failed", { error: err instanceof Error ? err.message : String(err) });
166
- }
167
- }
168
- async sleep(ms) {
169
- await new Promise((resolve) => setTimeout(resolve, ms));
170
- }
9
+ // src/queue/scaleway-sqs-queue.ts
10
+ import { randomUUID } from "crypto";
11
+ import {
12
+ DeleteMessageCommand,
13
+ ReceiveMessageCommand,
14
+ SendMessageCommand,
15
+ SQSClient
16
+ } from "@aws-sdk/client-sqs";
17
+ class ScalewaySqsJobQueue {
18
+ sqs;
19
+ queueUrl;
20
+ waitTimeSeconds;
21
+ maxNumberOfMessages;
22
+ visibilityTimeoutSeconds;
23
+ handlers = new Map;
24
+ logger;
25
+ running = false;
26
+ constructor(config) {
27
+ this.logger = config.logger;
28
+ const accessKeyId = config.credentials?.accessKeyId ?? process.env.SCALEWAY_ACCESS_KEY_QUEUE;
29
+ const secretAccessKey = config.credentials?.secretAccessKey ?? process.env.SCALEWAY_SECRET_KEY_QUEUE;
30
+ if (!accessKeyId || !secretAccessKey) {
31
+ throw new Error("Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env");
32
+ }
33
+ const region = config.region ?? process.env.SCALEWAY_REGION ?? "par";
34
+ const endpoint = config.endpoint ?? "https://sqs.mnq.fr-par.scaleway.com";
35
+ this.sqs = new SQSClient({
36
+ region,
37
+ endpoint,
38
+ credentials: {
39
+ accessKeyId,
40
+ secretAccessKey
41
+ }
42
+ });
43
+ this.queueUrl = config.queueUrl;
44
+ this.waitTimeSeconds = config.waitTimeSeconds ?? 20;
45
+ this.maxNumberOfMessages = config.maxNumberOfMessages ?? 5;
46
+ this.visibilityTimeoutSeconds = config.visibilityTimeoutSeconds ?? 60;
47
+ }
48
+ async enqueue(jobType, payload, options = {}) {
49
+ const id = randomUUID();
50
+ const now = new Date;
51
+ const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1000) : now;
52
+ const envelope = {
53
+ id,
54
+ type: jobType,
55
+ payload
56
+ };
57
+ await this.sqs.send(new SendMessageCommand({
58
+ QueueUrl: this.queueUrl,
59
+ MessageBody: JSON.stringify(envelope),
60
+ DelaySeconds: options.delaySeconds ?? 0
61
+ }));
62
+ return {
63
+ id,
64
+ type: jobType,
65
+ version: "1.0.0",
66
+ payload,
67
+ status: "pending",
68
+ priority: options.priority ?? 0,
69
+ attempts: 0,
70
+ maxRetries: options.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries,
71
+ createdAt: now,
72
+ updatedAt: now,
73
+ scheduledAt,
74
+ dedupeKey: options.dedupeKey,
75
+ tenantId: options.tenantId,
76
+ userId: options.userId,
77
+ traceId: options.traceId,
78
+ metadata: options.metadata
79
+ };
80
+ }
81
+ register(jobType, handler) {
82
+ if (this.handlers.has(jobType)) {
83
+ throw new Error(`Handler already registered for job type "${jobType}"`);
84
+ }
85
+ this.handlers.set(jobType, handler);
86
+ }
87
+ start() {
88
+ if (this.running)
89
+ return;
90
+ this.running = true;
91
+ this.pollLoop().catch((error) => {
92
+ this.logger?.error?.("jobs.queue.scaleway_sqs.poll_loop_fatal", {
93
+ error: error instanceof Error ? error.message : String(error)
94
+ });
95
+ this.running = false;
96
+ });
97
+ }
98
+ async stop() {
99
+ this.running = false;
100
+ }
101
+ async pollLoop() {
102
+ this.logger?.info?.("jobs.queue.scaleway_sqs.started", {
103
+ queueUrl: this.queueUrl
104
+ });
105
+ while (this.running) {
106
+ try {
107
+ const res = await this.sqs.send(new ReceiveMessageCommand({
108
+ QueueUrl: this.queueUrl,
109
+ MaxNumberOfMessages: this.maxNumberOfMessages,
110
+ WaitTimeSeconds: this.waitTimeSeconds,
111
+ VisibilityTimeout: this.visibilityTimeoutSeconds,
112
+ MessageSystemAttributeNames: ["ApproximateReceiveCount"]
113
+ }));
114
+ const messages = res.Messages ?? [];
115
+ if (messages.length === 0) {
116
+ continue;
117
+ }
118
+ for (const msg of messages) {
119
+ if (!msg.Body || !msg.ReceiptHandle) {
120
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.invalid_message", {
121
+ messageId: msg.MessageId,
122
+ reason: "missing_body_or_receipt"
123
+ });
124
+ continue;
125
+ }
126
+ let envelope;
127
+ try {
128
+ envelope = JSON.parse(msg.Body);
129
+ } catch (err) {
130
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.parse_failed", {
131
+ messageId: msg.MessageId,
132
+ error: err instanceof Error ? err.message : String(err)
133
+ });
134
+ await this.deleteMessage(msg.ReceiptHandle);
135
+ continue;
136
+ }
137
+ const handler = this.handlers.get(envelope.type);
138
+ if (!handler) {
139
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.missing_handler", {
140
+ jobType: envelope.type,
141
+ messageId: msg.MessageId
142
+ });
143
+ await this.deleteMessage(msg.ReceiptHandle);
144
+ continue;
145
+ }
146
+ const now = new Date;
147
+ const attempts = parseInt(msg.Attributes?.ApproximateReceiveCount ?? "1", 10);
148
+ const job = {
149
+ id: envelope.id,
150
+ type: envelope.type,
151
+ version: "1.0.0",
152
+ payload: envelope.payload,
153
+ status: "pending",
154
+ priority: 0,
155
+ attempts,
156
+ maxRetries: DEFAULT_RETRY_POLICY.maxRetries,
157
+ createdAt: now,
158
+ updatedAt: now
159
+ };
160
+ job.status = "running";
161
+ job.updatedAt = new Date;
162
+ try {
163
+ await handler(job);
164
+ job.status = "completed";
165
+ job.updatedAt = new Date;
166
+ await this.deleteMessage(msg.ReceiptHandle);
167
+ } catch (err) {
168
+ job.status = "failed";
169
+ job.lastError = err instanceof Error ? err.message : "Unknown job error";
170
+ job.updatedAt = new Date;
171
+ this.logger?.error?.("jobs.queue.scaleway_sqs.job_failed", {
172
+ jobType: job.type,
173
+ jobId: job.id,
174
+ error: err instanceof Error ? err.message : String(err)
175
+ });
176
+ }
177
+ }
178
+ } catch (err) {
179
+ this.logger?.error?.("jobs.queue.scaleway_sqs.poll_error", {
180
+ error: err instanceof Error ? err.message : String(err)
181
+ });
182
+ await this.sleep(5000);
183
+ }
184
+ }
185
+ this.logger?.info?.("jobs.queue.scaleway_sqs.stopped", {
186
+ queueUrl: this.queueUrl
187
+ });
188
+ }
189
+ async deleteMessage(receiptHandle) {
190
+ try {
191
+ await this.sqs.send(new DeleteMessageCommand({
192
+ QueueUrl: this.queueUrl,
193
+ ReceiptHandle: receiptHandle
194
+ }));
195
+ } catch (err) {
196
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.delete_failed", {
197
+ error: err instanceof Error ? err.message : String(err)
198
+ });
199
+ }
200
+ }
201
+ async sleep(ms) {
202
+ await new Promise((resolve) => setTimeout(resolve, ms));
203
+ }
204
+ }
205
+ export {
206
+ ScalewaySqsJobQueue
171
207
  };
172
-
173
- //#endregion
174
- export { ScalewaySqsJobQueue };
175
- //# sourceMappingURL=scaleway-sqs-queue.js.map
@@ -1,9 +1,3 @@
1
- import { __exportAll, __reExport } from "../_virtual/_rolldown/runtime.js";
2
- export * from "@contractspec/lib.contracts/jobs/queue";
3
-
4
- //#region src/queue/types.d.ts
5
-
6
- import * as import__contractspec_lib_contracts_jobs_queue from "@contractspec/lib.contracts/jobs/queue";
7
- //#endregion
8
- export { import__contractspec_lib_contracts_jobs_queue as types_d_exports };
1
+ export * from '@contractspec/lib.contracts/jobs/queue';
2
+ export { calculateBackoff, DEFAULT_RETRY_POLICY, } from '@contractspec/lib.contracts/jobs/queue';
9
3
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/queue/types.ts"],"mappings":""}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/queue/types.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,wCAAwC,CAAC"}
@@ -1,12 +1,11 @@
1
- import { __exportAll, __reExport } from "../_virtual/_rolldown/runtime.js";
2
-
3
- export * from "@contractspec/lib.contracts/jobs/queue"
4
-
5
- //#region src/queue/types.ts
6
- var types_exports = /* @__PURE__ */ __exportAll({});
7
- import * as import__contractspec_lib_contracts_jobs_queue from "@contractspec/lib.contracts/jobs/queue";
8
- __reExport(types_exports, import__contractspec_lib_contracts_jobs_queue);
9
-
10
- //#endregion
11
- export { types_exports };
12
- //# sourceMappingURL=types.js.map
1
+ // @bun
2
+ // src/queue/types.ts
3
+ export * from "@contractspec/lib.contracts/jobs/queue";
4
+ import {
5
+ calculateBackoff,
6
+ DEFAULT_RETRY_POLICY
7
+ } from "@contractspec/lib.contracts/jobs/queue";
8
+ export {
9
+ calculateBackoff,
10
+ DEFAULT_RETRY_POLICY
11
+ };
@@ -1,92 +1,88 @@
1
- import { types_d_exports } from "../queue/types.js";
2
-
3
- //#region src/scheduler/index.d.ts
1
+ import type { JobQueue, EnqueueOptions } from '../queue/types';
4
2
  /**
5
3
  * Scheduled job configuration.
6
4
  */
7
- interface ScheduledJobConfig {
8
- /** Unique name for the schedule */
9
- name: string;
10
- /** Cron expression (e.g., '0 0 * * *' for daily at midnight) */
11
- cronExpression: string;
12
- /** Job type to enqueue */
13
- jobType: string;
14
- /** Job payload (can be a function for dynamic payloads) */
15
- payload?: unknown | (() => unknown | Promise<unknown>);
16
- /** Enqueue options */
17
- options?: types_d_exports.EnqueueOptions;
18
- /** Timezone for cron evaluation (default: UTC) */
19
- timezone?: string;
20
- /** Whether the schedule is enabled */
21
- enabled?: boolean;
22
- /** Description */
23
- description?: string;
5
+ export interface ScheduledJobConfig {
6
+ /** Unique name for the schedule */
7
+ name: string;
8
+ /** Cron expression (e.g., '0 0 * * *' for daily at midnight) */
9
+ cronExpression: string;
10
+ /** Job type to enqueue */
11
+ jobType: string;
12
+ /** Job payload (can be a function for dynamic payloads) */
13
+ payload?: unknown | (() => unknown | Promise<unknown>);
14
+ /** Enqueue options */
15
+ options?: EnqueueOptions;
16
+ /** Timezone for cron evaluation (default: UTC) */
17
+ timezone?: string;
18
+ /** Whether the schedule is enabled */
19
+ enabled?: boolean;
20
+ /** Description */
21
+ description?: string;
24
22
  }
25
23
  /**
26
24
  * Active scheduled job with next run time.
27
25
  */
28
- interface ActiveSchedule extends ScheduledJobConfig {
29
- nextRun: Date | null;
30
- lastRun: Date | null;
26
+ export interface ActiveSchedule extends ScheduledJobConfig {
27
+ nextRun: Date | null;
28
+ lastRun: Date | null;
31
29
  }
32
30
  /**
33
31
  * Job scheduler for recurring jobs.
34
32
  */
35
- declare class JobScheduler {
36
- private readonly queue;
37
- private readonly schedules;
38
- private timer?;
39
- private readonly checkIntervalMs;
40
- constructor(queue: types_d_exports.JobQueue, options?: {
41
- checkIntervalMs?: number;
42
- });
43
- /**
44
- * Add a scheduled job.
45
- */
46
- schedule(config: ScheduledJobConfig): void;
47
- /**
48
- * Remove a scheduled job.
49
- */
50
- unschedule(name: string): boolean;
51
- /**
52
- * Enable a scheduled job.
53
- */
54
- enable(name: string): boolean;
55
- /**
56
- * Disable a scheduled job.
57
- */
58
- disable(name: string): boolean;
59
- /**
60
- * Get all schedules.
61
- */
62
- getSchedules(): ActiveSchedule[];
63
- /**
64
- * Get a specific schedule.
65
- */
66
- getSchedule(name: string): ActiveSchedule | undefined;
67
- /**
68
- * Start the scheduler.
69
- */
70
- start(): void;
71
- /**
72
- * Stop the scheduler.
73
- */
74
- stop(): void;
75
- /**
76
- * Check and enqueue due schedules.
77
- */
78
- private checkSchedules;
33
+ export declare class JobScheduler {
34
+ private readonly queue;
35
+ private readonly schedules;
36
+ private timer?;
37
+ private readonly checkIntervalMs;
38
+ constructor(queue: JobQueue, options?: {
39
+ checkIntervalMs?: number;
40
+ });
41
+ /**
42
+ * Add a scheduled job.
43
+ */
44
+ schedule(config: ScheduledJobConfig): void;
45
+ /**
46
+ * Remove a scheduled job.
47
+ */
48
+ unschedule(name: string): boolean;
49
+ /**
50
+ * Enable a scheduled job.
51
+ */
52
+ enable(name: string): boolean;
53
+ /**
54
+ * Disable a scheduled job.
55
+ */
56
+ disable(name: string): boolean;
57
+ /**
58
+ * Get all schedules.
59
+ */
60
+ getSchedules(): ActiveSchedule[];
61
+ /**
62
+ * Get a specific schedule.
63
+ */
64
+ getSchedule(name: string): ActiveSchedule | undefined;
65
+ /**
66
+ * Start the scheduler.
67
+ */
68
+ start(): void;
69
+ /**
70
+ * Stop the scheduler.
71
+ */
72
+ stop(): void;
73
+ /**
74
+ * Check and enqueue due schedules.
75
+ */
76
+ private checkSchedules;
79
77
  }
80
78
  /**
81
79
  * Create a job scheduler instance.
82
80
  */
83
- declare function createScheduler(queue: types_d_exports.JobQueue, options?: {
84
- checkIntervalMs?: number;
81
+ export declare function createScheduler(queue: JobQueue, options?: {
82
+ checkIntervalMs?: number;
85
83
  }): JobScheduler;
86
84
  /**
87
85
  * Helper to define a scheduled job configuration.
88
86
  */
89
- declare function defineSchedule(config: ScheduledJobConfig): ScheduledJobConfig;
90
- //#endregion
91
- export { ActiveSchedule, JobScheduler, ScheduledJobConfig, createScheduler, defineSchedule };
87
+ export declare function defineSchedule(config: ScheduledJobConfig): ScheduledJobConfig;
92
88
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/scheduler/index.ts"],"mappings":";;;;;AAKA;UA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