@nicnocquee/dataqueue 1.25.0 → 1.26.0-beta.20260223195940
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/ai/build-docs-content.ts +96 -0
- package/ai/build-llms-full.ts +42 -0
- package/ai/docs-content.json +278 -0
- package/ai/rules/advanced.md +132 -0
- package/ai/rules/basic.md +159 -0
- package/ai/rules/react-dashboard.md +83 -0
- package/ai/skills/dataqueue-advanced/SKILL.md +320 -0
- package/ai/skills/dataqueue-core/SKILL.md +234 -0
- package/ai/skills/dataqueue-react/SKILL.md +189 -0
- package/dist/cli.cjs +1149 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +66 -1
- package/dist/cli.d.ts +66 -1
- package/dist/cli.js +1146 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3157 -1237
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +613 -23
- package/dist/index.d.ts +613 -23
- package/dist/index.js +3156 -1238
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.cjs +186 -0
- package/dist/mcp-server.cjs.map +1 -0
- package/dist/mcp-server.d.cts +32 -0
- package/dist/mcp-server.d.ts +32 -0
- package/dist/mcp-server.js +175 -0
- package/dist/mcp-server.js.map +1 -0
- package/migrations/1781200000004_create_cron_schedules_table.sql +33 -0
- package/migrations/1781200000005_add_retry_config_to_job_queue.sql +17 -0
- package/package.json +24 -21
- package/src/backend.ts +170 -5
- package/src/backends/postgres.ts +992 -63
- package/src/backends/redis-scripts.ts +358 -26
- package/src/backends/redis.test.ts +1363 -0
- package/src/backends/redis.ts +993 -35
- package/src/cli.test.ts +82 -6
- package/src/cli.ts +73 -10
- package/src/cron.test.ts +126 -0
- package/src/cron.ts +40 -0
- package/src/db-util.ts +1 -1
- package/src/index.test.ts +682 -0
- package/src/index.ts +209 -34
- package/src/init-command.test.ts +449 -0
- package/src/init-command.ts +709 -0
- package/src/install-mcp-command.test.ts +216 -0
- package/src/install-mcp-command.ts +185 -0
- package/src/install-rules-command.test.ts +218 -0
- package/src/install-rules-command.ts +233 -0
- package/src/install-skills-command.test.ts +176 -0
- package/src/install-skills-command.ts +124 -0
- package/src/mcp-server.test.ts +162 -0
- package/src/mcp-server.ts +231 -0
- package/src/processor.ts +36 -97
- package/src/queue.test.ts +465 -0
- package/src/queue.ts +34 -252
- package/src/supervisor.test.ts +340 -0
- package/src/supervisor.ts +162 -0
- package/src/types.ts +388 -12
- package/LICENSE +0 -21
package/src/backend.ts
CHANGED
|
@@ -6,6 +6,12 @@ import {
|
|
|
6
6
|
FailureReason,
|
|
7
7
|
TagQueryMode,
|
|
8
8
|
JobType,
|
|
9
|
+
CronScheduleRecord,
|
|
10
|
+
CronScheduleStatus,
|
|
11
|
+
EditCronScheduleOptions,
|
|
12
|
+
WaitpointRecord,
|
|
13
|
+
CreateTokenOptions,
|
|
14
|
+
AddJobOptions,
|
|
9
15
|
} from './types.js';
|
|
10
16
|
|
|
11
17
|
/**
|
|
@@ -34,6 +40,31 @@ export interface JobUpdates {
|
|
|
34
40
|
runAt?: Date | null;
|
|
35
41
|
timeoutMs?: number | null;
|
|
36
42
|
tags?: string[] | null;
|
|
43
|
+
retryDelay?: number | null;
|
|
44
|
+
retryBackoff?: boolean | null;
|
|
45
|
+
retryDelayMax?: number | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Input shape for creating a cron schedule in the backend.
|
|
50
|
+
* This is the backend-level version of CronScheduleOptions.
|
|
51
|
+
*/
|
|
52
|
+
export interface CronScheduleInput {
|
|
53
|
+
scheduleName: string;
|
|
54
|
+
cronExpression: string;
|
|
55
|
+
jobType: string;
|
|
56
|
+
payload: any;
|
|
57
|
+
maxAttempts: number;
|
|
58
|
+
priority: number;
|
|
59
|
+
timeoutMs: number | null;
|
|
60
|
+
forceKillOnTimeout: boolean;
|
|
61
|
+
tags: string[] | undefined;
|
|
62
|
+
timezone: string;
|
|
63
|
+
allowOverlap: boolean;
|
|
64
|
+
nextRunAt: Date | null;
|
|
65
|
+
retryDelay: number | null;
|
|
66
|
+
retryBackoff: boolean | null;
|
|
67
|
+
retryDelayMax: number | null;
|
|
37
68
|
}
|
|
38
69
|
|
|
39
70
|
/**
|
|
@@ -44,11 +75,34 @@ export interface JobUpdates {
|
|
|
44
75
|
export interface QueueBackend {
|
|
45
76
|
// ── Job CRUD ──────────────────────────────────────────────────────────
|
|
46
77
|
|
|
47
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Add a job and return its numeric ID.
|
|
80
|
+
*
|
|
81
|
+
* @param job - Job configuration.
|
|
82
|
+
* @param options - Optional. Pass `{ db }` to run the INSERT on an external
|
|
83
|
+
* client (e.g., inside a transaction). PostgreSQL only.
|
|
84
|
+
*/
|
|
48
85
|
addJob<PayloadMap, T extends JobType<PayloadMap>>(
|
|
49
86
|
job: JobOptions<PayloadMap, T>,
|
|
87
|
+
options?: AddJobOptions,
|
|
50
88
|
): Promise<number>;
|
|
51
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Add multiple jobs in a single operation and return their IDs.
|
|
92
|
+
*
|
|
93
|
+
* IDs are returned in the same order as the input array.
|
|
94
|
+
* Each job may independently have an `idempotencyKey`; duplicates
|
|
95
|
+
* resolve to the existing job's ID without creating a new row.
|
|
96
|
+
*
|
|
97
|
+
* @param jobs - Array of job configurations.
|
|
98
|
+
* @param options - Optional. Pass `{ db }` to run the INSERTs on an external
|
|
99
|
+
* client (e.g., inside a transaction). PostgreSQL only.
|
|
100
|
+
*/
|
|
101
|
+
addJobs<PayloadMap, T extends JobType<PayloadMap>>(
|
|
102
|
+
jobs: JobOptions<PayloadMap, T>[],
|
|
103
|
+
options?: AddJobOptions,
|
|
104
|
+
): Promise<number[]>;
|
|
105
|
+
|
|
52
106
|
/** Get a single job by ID, or null if not found. */
|
|
53
107
|
getJob<PayloadMap, T extends JobType<PayloadMap>>(
|
|
54
108
|
id: number,
|
|
@@ -127,11 +181,11 @@ export interface QueueBackend {
|
|
|
127
181
|
updates: JobUpdates,
|
|
128
182
|
): Promise<number>;
|
|
129
183
|
|
|
130
|
-
/** Delete completed jobs older than N days. Returns count deleted. */
|
|
131
|
-
cleanupOldJobs(daysToKeep?: number): Promise<number>;
|
|
184
|
+
/** Delete completed jobs older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
185
|
+
cleanupOldJobs(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
132
186
|
|
|
133
|
-
/** Delete job events older than N days. Returns count deleted. */
|
|
134
|
-
cleanupOldJobEvents(daysToKeep?: number): Promise<number>;
|
|
187
|
+
/** Delete job events older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
188
|
+
cleanupOldJobEvents(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
135
189
|
|
|
136
190
|
/** Reclaim jobs stuck in 'processing' for too long. Returns count. */
|
|
137
191
|
reclaimStuckJobs(maxProcessingTimeMinutes?: number): Promise<number>;
|
|
@@ -153,6 +207,117 @@ export interface QueueBackend {
|
|
|
153
207
|
/** Get all events for a job, ordered by createdAt ASC. */
|
|
154
208
|
getJobEvents(jobId: number): Promise<JobEvent[]>;
|
|
155
209
|
|
|
210
|
+
// ── Cron schedules ──────────────────────────────────────────────────
|
|
211
|
+
|
|
212
|
+
/** Create a cron schedule and return its ID. */
|
|
213
|
+
addCronSchedule(input: CronScheduleInput): Promise<number>;
|
|
214
|
+
|
|
215
|
+
/** Get a cron schedule by ID, or null if not found. */
|
|
216
|
+
getCronSchedule(id: number): Promise<CronScheduleRecord | null>;
|
|
217
|
+
|
|
218
|
+
/** Get a cron schedule by its unique name, or null if not found. */
|
|
219
|
+
getCronScheduleByName(name: string): Promise<CronScheduleRecord | null>;
|
|
220
|
+
|
|
221
|
+
/** List cron schedules, optionally filtered by status. */
|
|
222
|
+
listCronSchedules(status?: CronScheduleStatus): Promise<CronScheduleRecord[]>;
|
|
223
|
+
|
|
224
|
+
/** Delete a cron schedule by ID. */
|
|
225
|
+
removeCronSchedule(id: number): Promise<void>;
|
|
226
|
+
|
|
227
|
+
/** Pause a cron schedule. */
|
|
228
|
+
pauseCronSchedule(id: number): Promise<void>;
|
|
229
|
+
|
|
230
|
+
/** Resume a cron schedule. */
|
|
231
|
+
resumeCronSchedule(id: number): Promise<void>;
|
|
232
|
+
|
|
233
|
+
/** Edit a cron schedule. */
|
|
234
|
+
editCronSchedule(
|
|
235
|
+
id: number,
|
|
236
|
+
updates: EditCronScheduleOptions,
|
|
237
|
+
nextRunAt?: Date | null,
|
|
238
|
+
): Promise<void>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Atomically fetch all active cron schedules whose nextRunAt <= now.
|
|
242
|
+
* In PostgreSQL this uses FOR UPDATE SKIP LOCKED to prevent duplicate enqueuing.
|
|
243
|
+
*/
|
|
244
|
+
getDueCronSchedules(): Promise<CronScheduleRecord[]>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Update a cron schedule after a job has been enqueued.
|
|
248
|
+
* Sets lastEnqueuedAt, lastJobId, and advances nextRunAt.
|
|
249
|
+
*/
|
|
250
|
+
updateCronScheduleAfterEnqueue(
|
|
251
|
+
id: number,
|
|
252
|
+
lastEnqueuedAt: Date,
|
|
253
|
+
lastJobId: number,
|
|
254
|
+
nextRunAt: Date | null,
|
|
255
|
+
): Promise<void>;
|
|
256
|
+
|
|
257
|
+
// ── Wait / step-data support ────────────────────────────────────────
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Transition a job from 'processing' to 'waiting' status.
|
|
261
|
+
* Persists step data so the handler can resume from where it left off.
|
|
262
|
+
*
|
|
263
|
+
* @param jobId - The job to pause.
|
|
264
|
+
* @param options - Wait configuration including optional waitUntil date, token ID, and step data.
|
|
265
|
+
*/
|
|
266
|
+
waitJob(
|
|
267
|
+
jobId: number,
|
|
268
|
+
options: {
|
|
269
|
+
waitUntil?: Date;
|
|
270
|
+
waitTokenId?: string;
|
|
271
|
+
stepData: Record<string, any>;
|
|
272
|
+
},
|
|
273
|
+
): Promise<void>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Persist step data for a job. Called after each `ctx.run()` step completes
|
|
277
|
+
* to save intermediate progress. Best-effort: should not throw.
|
|
278
|
+
*
|
|
279
|
+
* @param jobId - The job to update.
|
|
280
|
+
* @param stepData - The step data to persist.
|
|
281
|
+
*/
|
|
282
|
+
updateStepData(jobId: number, stepData: Record<string, any>): Promise<void>;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Create a waitpoint token that can pause a job until an external signal completes it.
|
|
286
|
+
*
|
|
287
|
+
* @param jobId - The job ID to associate with the token (null if created outside a handler).
|
|
288
|
+
* @param options - Optional timeout string (e.g. '10m', '1h') and tags.
|
|
289
|
+
* @returns The created waitpoint with its unique ID.
|
|
290
|
+
*/
|
|
291
|
+
createWaitpoint(
|
|
292
|
+
jobId: number | null,
|
|
293
|
+
options?: CreateTokenOptions,
|
|
294
|
+
): Promise<{ id: string }>;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Complete a waitpoint token, optionally providing output data.
|
|
298
|
+
* Moves the associated job from 'waiting' back to 'pending' so it gets picked up.
|
|
299
|
+
*
|
|
300
|
+
* @param tokenId - The waitpoint token ID to complete.
|
|
301
|
+
* @param data - Optional data to pass to the waiting handler.
|
|
302
|
+
*/
|
|
303
|
+
completeWaitpoint(tokenId: string, data?: any): Promise<void>;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Retrieve a waitpoint token by its ID.
|
|
307
|
+
*
|
|
308
|
+
* @param tokenId - The waitpoint token ID to look up.
|
|
309
|
+
* @returns The waitpoint record, or null if not found.
|
|
310
|
+
*/
|
|
311
|
+
getWaitpoint(tokenId: string): Promise<WaitpointRecord | null>;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Expire timed-out waitpoint tokens and move their associated jobs back to 'pending'.
|
|
315
|
+
* Should be called periodically (e.g., alongside reclaimStuckJobs).
|
|
316
|
+
*
|
|
317
|
+
* @returns The number of tokens that were expired.
|
|
318
|
+
*/
|
|
319
|
+
expireTimedOutWaitpoints(): Promise<number>;
|
|
320
|
+
|
|
156
321
|
// ── Internal helpers ──────────────────────────────────────────────────
|
|
157
322
|
|
|
158
323
|
/** Set a pending reason for unpicked jobs of a given type. */
|