@softure-ai/jobs 0.1.0 → 0.1.1
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 +12 -0
- package/README.md +75 -10
- package/dist/index.d.ts +54 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +57 -4
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +40 -10
- package/dist/options.js.map +1 -1
- package/dist/schema.d.ts +92 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +8 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/claim.d.ts +4 -1
- package/dist/server/claim.d.ts.map +1 -1
- package/dist/server/claim.js +13 -3
- package/dist/server/claim.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/maintenance.d.ts +5 -2
- package/dist/server/maintenance.d.ts.map +1 -1
- package/dist/server/maintenance.js +5 -3
- package/dist/server/maintenance.js.map +1 -1
- package/dist/server/run-due.d.ts +1 -1
- package/dist/server/run-due.d.ts.map +1 -1
- package/dist/server/run-due.js +3 -1
- package/dist/server/run-due.js.map +1 -1
- package/dist/server/schedules.d.ts +45 -0
- package/dist/server/schedules.d.ts.map +1 -0
- package/dist/server/schedules.js +97 -0
- package/dist/server/schedules.js.map +1 -0
- package/dist/worker/run-job-worker.d.ts.map +1 -1
- package/dist/worker/run-job-worker.js +21 -3
- package/dist/worker/run-job-worker.js.map +1 -1
- package/migrations/0002_create_schedules.sql +12 -0
- package/module.json +2 -2
- package/package.json +1 -1
- package/src/index.ts +11 -4
- package/src/options.ts +61 -25
- package/src/schema.ts +9 -1
- package/src/server/claim.ts +11 -3
- package/src/server/index.ts +7 -0
- package/src/server/maintenance.ts +7 -3
- package/src/server/run-due.ts +3 -1
- package/src/server/schedules.ts +121 -0
- package/src/worker/run-job-worker.ts +18 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
|
|
|
4
4
|
production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
5
|
"Definition of done").
|
|
6
6
|
|
|
7
|
+
## 0.1.1
|
|
8
|
+
|
|
9
|
+
- Recurring schedules (#491): `jobs({ schedules: { "<queue>": { every: "1h", payload } } })`. Workers enqueue each
|
|
10
|
+
period's run once, however many run (a conditional upsert of the new table `jobs.schedules`, migration
|
|
11
|
+
`0002_create_schedules.sql`, in the same transaction as the job); missed periods collapse into one run; while a run
|
|
12
|
+
is still live the next period joins it. A schedule's queue takes the default queue settings unless `queues` names
|
|
13
|
+
it, and `queues` may be left out when schedules define them. `runDueJobs` enqueues due runs first;
|
|
14
|
+
`enqueueDueSchedules` serves apps that drain from a cron. `getQueueStats` reports each queue's `schedule`
|
|
15
|
+
(`everySeconds`, `lastEnqueuedAt`, `lastSucceededAt`, `isLate`). auth, mcp-access, waitlist, security and analytics
|
|
16
|
+
ship their prune handlers and schedules in their `./jobs` entries.
|
|
17
|
+
|
|
7
18
|
## 0.1.0
|
|
8
19
|
|
|
9
20
|
- First version (#471): background jobs in Postgres (`jobs.jobs`). `jobs({ queues })` in `softure.config.ts`;
|
|
@@ -13,3 +24,4 @@ production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../
|
|
|
13
24
|
lease, a heartbeat for long jobs, fenced completion, retry with exponential backoff and jitter, a terminal `failed`
|
|
14
25
|
state, pruning, and release of unfinished jobs on SIGTERM; `runDueJobs` (`@softure-ai/jobs/testing`) runs due jobs
|
|
15
26
|
in-process for tests and cron-driven apps.
|
|
27
|
+
|
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@ received message.
|
|
|
9
9
|
|
|
10
10
|
A job queue in one table (`jobs.jobs`) with enqueue inside the caller's transaction and dedup keys, claims with
|
|
11
11
|
`FOR UPDATE SKIP LOCKED` under a lease, fenced completion, retry with exponential backoff, a worker process with
|
|
12
|
-
graceful shutdown,
|
|
12
|
+
graceful shutdown, recurring schedules that run once per period however many workers run, and an in-process runner
|
|
13
|
+
for tests and cron-driven apps.
|
|
13
14
|
|
|
14
15
|
## 2. Installation
|
|
15
16
|
|
|
@@ -46,12 +47,15 @@ export default defineSoftureConfig({
|
|
|
46
47
|
| `queues.<name>.backoff` | `{ baseSeconds: 10, maxSeconds: 3600 }` | delay after attempt n is `min(max, base * 2^(n-1))`, shortened by up to 20 % at random |
|
|
47
48
|
| `queues.<name>.leaseSeconds` | `300` | how long a claimed job is reserved; the worker extends it while the handler runs, so it bounds how long a crashed worker's job waits, not how long a handler may take |
|
|
48
49
|
| `queues.<name>.concurrency` | `1` | jobs of the queue one worker process runs at once |
|
|
50
|
+
| `schedules.<queue>.every` | (required) | how often the schedule runs: `<n>m`, `<n>h` or `<n>d`, from `1m` to `7d` (§3, "Schedules") |
|
|
51
|
+
| `schedules.<queue>.payload` | `{}` | the payload of every scheduled run |
|
|
49
52
|
| `pollIntervalMs` | `1000` | how often an idle worker looks for due jobs |
|
|
50
53
|
| `shutdownGraceMs` | `20000` | how long a stopping worker waits for running handlers before releasing their jobs |
|
|
51
54
|
| `retention` | `{ succeededDays: 7, failedDays: 30, cancelledDays: 7 }` | how long finished jobs are kept; the worker prunes once an hour |
|
|
52
55
|
|
|
53
56
|
A queue name is lowercase letters, digits, `_`, `.` and `-`. A queue the config does not define is refused by
|
|
54
|
-
`enqueueJob` and by the worker: a typo is a bug, not a new queue.
|
|
57
|
+
`enqueueJob` and by the worker: a typo is a bug, not a new queue. A schedule defines its queue too, with the default
|
|
58
|
+
settings unless `queues` names it; the config needs at least one queue or schedule.
|
|
55
59
|
|
|
56
60
|
### Handlers
|
|
57
61
|
|
|
@@ -148,11 +152,67 @@ logged and retried on the next round; a database restart does not end the worker
|
|
|
148
152
|
`runJobWorker({ db, config, handlers, signal })` is the loop without the process part, for an app that runs it inside
|
|
149
153
|
a process of its own.
|
|
150
154
|
|
|
155
|
+
### Schedules
|
|
156
|
+
|
|
157
|
+
A schedule runs its queue's handler once per period, instead of an app cron:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { authJobSchedules } from "@softure-ai/auth/jobs";
|
|
161
|
+
import { securityJobSchedules } from "@softure-ai/security/jobs";
|
|
162
|
+
|
|
163
|
+
jobs({
|
|
164
|
+
schedules: {
|
|
165
|
+
...authJobSchedules, // auth.prune-sessions hourly, auth.prune-password-resets daily
|
|
166
|
+
...securityJobSchedules, // security.prune-rate-limits hourly
|
|
167
|
+
"app.digest": { every: "1d", payload: { kind: "weekly" } },
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// src/jobs/handlers.ts: the packages' handlers next to the app's own
|
|
174
|
+
import { authJobHandlers } from "@softure-ai/auth/jobs";
|
|
175
|
+
import { securityJobHandlers } from "@softure-ai/security/jobs";
|
|
176
|
+
|
|
177
|
+
export const handlers: JobHandlers = { ...authJobHandlers, ...securityJobHandlers, "app.digest": digestHandler };
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
- Periods start on whole multiples of `every` counted from 1970-01-01 00:00 UTC: `1h` on the full hour, `1d` at
|
|
181
|
+
midnight UTC, `15m` at :00, :15, :30, :45. A run is due at the start of its period.
|
|
182
|
+
- Once per period, however many workers run: a worker takes a period with a conditional upsert of
|
|
183
|
+
`jobs.schedules` (the period must be later than the stored one) and enqueues the run in the same transaction, so a
|
|
184
|
+
missed or doubled tick cannot happen. A worker enqueues only the schedules of the queues it runs.
|
|
185
|
+
- Missed periods (no worker ran) collapse into one run for the current period.
|
|
186
|
+
- Every scheduled run has the dedup key `schedule`: while a run is still pending or running (retrying a failure), the
|
|
187
|
+
next period joins it instead of queueing a second run behind it.
|
|
188
|
+
- Scheduled runs are ordinary jobs: retries, `maxAttempts`, `getJob`, `retryJob` and pruning apply.
|
|
189
|
+
- A package's prune handlers live in its `./jobs` entry (`@softure-ai/auth/jobs`, `@softure-ai/mcp-access/jobs`,
|
|
190
|
+
`@softure-ai/waitlist/jobs`, `@softure-ai/security/jobs`, `@softure-ai/analytics/jobs`), with `@softure-ai/jobs` as an
|
|
191
|
+
optional peer.
|
|
192
|
+
|
|
193
|
+
`getQueueStats` reports each scheduled queue's `schedule`: `everySeconds`, `lastEnqueuedAt` (the start of the latest
|
|
194
|
+
period a run was enqueued for), `lastSucceededAt` (any succeeded job of the queue, a run enqueued by hand too) and
|
|
195
|
+
`isLate`: no success within two periods, counted from when a worker first saw the schedule, or no worker has seen it
|
|
196
|
+
at all. The module's health check does not fail on a late schedule (a late cleanup must not take the app out of
|
|
197
|
+
rotation); an app that wants an alarm adds a check of its own:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
ops({
|
|
201
|
+
checks: {
|
|
202
|
+
"app.schedules": async (context) => {
|
|
203
|
+
const late = (await getQueueStats(context as JobsContext)).filter((stats) => stats.schedule?.isLate === true);
|
|
204
|
+
return late.length === 0 ? ok() : err("app.schedules_late");
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
151
210
|
### Without a worker
|
|
152
211
|
|
|
153
|
-
`runDueJobs(ctx, { handlers })` (from `@softure-ai/jobs/server` or `/testing`)
|
|
154
|
-
|
|
155
|
-
`pruneJobs(ctx)` from the same cron.
|
|
212
|
+
`runDueJobs(ctx, { handlers })` (from `@softure-ai/jobs/server` or `/testing`) enqueues the due runs of the schedules
|
|
213
|
+
among its queues, then runs every due job once, in this process, one after another, and returns
|
|
214
|
+
`{ succeeded, retried, failed, stale }`. A cron can drain a queue with it; call `pruneJobs(ctx)` from the same cron.
|
|
215
|
+
`enqueueDueSchedules(ctx, { queues? })` only enqueues the due scheduled runs.
|
|
156
216
|
|
|
157
217
|
### Steering and overview
|
|
158
218
|
|
|
@@ -163,7 +223,7 @@ From `@softure-ai/jobs/server`, each on `ctx = { db, clock, config }`:
|
|
|
163
223
|
| `getJob(ctx, id)` | the `Job` or `null` |
|
|
164
224
|
| `cancelJob(ctx, id)` | a pending job becomes `cancelled`; `jobs.not_cancellable` for a running or finished one, `jobs.not_found` |
|
|
165
225
|
| `retryJob(ctx, id)` | a failed or cancelled job runs again from scratch (attempts 0, due now); `jobs.not_retryable`, `jobs.dedup_key_taken` while a live job has its key, `jobs.not_found` |
|
|
166
|
-
| `getQueueStats(ctx)` | per queue: counts per status, the due backlog
|
|
226
|
+
| `getQueueStats(ctx)` | per queue: counts per status, the due backlog, the `run_at` of its oldest due job and its `schedule` (or `null`) |
|
|
167
227
|
| `pruneJobs(ctx)` | deletes finished jobs past their retention; returns the count |
|
|
168
228
|
|
|
169
229
|
`getQueueStats` suits an app health check of its own, `ops({ checks: { "app.jobs": … } })`, e.g. unavailable when the
|
|
@@ -176,7 +236,7 @@ Nothing to mount: the module has no routes or pages. The worker is a process (§
|
|
|
176
236
|
|
|
177
237
|
## 5. Migrations and tables
|
|
178
238
|
|
|
179
|
-
Schema `jobs`,
|
|
239
|
+
Schema `jobs`, two tables, `migrations/0001_create_jobs.sql` and `migrations/0002_create_schedules.sql`:
|
|
180
240
|
|
|
181
241
|
`jobs.jobs`: `id` (bigint identity; a string in the API), `queue`, `payload` (jsonb), `status` (`pending`, `running`,
|
|
182
242
|
`succeeded`, `failed`, `cancelled`), `attempts`, `max_attempts`, `run_at`, `locked_until`, `locked_by` (the worker,
|
|
@@ -184,7 +244,11 @@ Schema `jobs`, one table, `migrations/0001_create_jobs.sql`:
|
|
|
184
244
|
`updated_at`, `finished_at`. Checks keep the lease columns set exactly while `running` and `finished_at` set exactly
|
|
185
245
|
for finished jobs; a partial unique index allows one live job per queue and dedup key.
|
|
186
246
|
|
|
187
|
-
|
|
247
|
+
`jobs.schedules`: `name` (the schedule's queue, primary key), `last_slot_at` (the start of the latest period a run
|
|
248
|
+
was enqueued for), `last_succeeded_at`, `created_at`, `updated_at`. One row per schedule a worker has seen; a row of
|
|
249
|
+
a schedule removed from the config stays and is ignored.
|
|
250
|
+
|
|
251
|
+
The app role needs `SELECT, INSERT, UPDATE, DELETE` on the tables, which the `@softure-ai/ops` roles recipe grants on
|
|
188
252
|
every schema the migrator creates.
|
|
189
253
|
|
|
190
254
|
## 6. Environment variables
|
|
@@ -207,7 +271,8 @@ No UI.
|
|
|
207
271
|
## 10. Hooks
|
|
208
272
|
|
|
209
273
|
The handlers (§3) are the app's code. `logger` (`info`, `warn`, `error`; `@softure-ai/observability`'s `Logger` fits)
|
|
210
|
-
receives the worker's lines: started, stopped, a thrown handler with its error, a lost lease,
|
|
274
|
+
receives the worker's lines: started, stopped, a scheduled run enqueued, a thrown handler with its error, a lost lease,
|
|
275
|
+
a release, pruning.
|
|
211
276
|
|
|
212
277
|
## 11. GDPR
|
|
213
278
|
|
|
@@ -218,7 +283,7 @@ logger gets payload paths, never values, for a payload that does not match its s
|
|
|
218
283
|
## 12. Limitations
|
|
219
284
|
|
|
220
285
|
- Polling, no `LISTEN/NOTIFY`: a job waits up to `pollIntervalMs` when the worker is idle.
|
|
221
|
-
-
|
|
286
|
+
- Schedules take a fixed period (`every`), aligned to UTC; no cron expressions, no time zones, no "at 03:00".
|
|
222
287
|
- No priorities within a queue and no rate limits per queue beyond `concurrency`; split work into queues instead.
|
|
223
288
|
- At-least-once delivery (§3, "Handlers run at least once").
|
|
224
289
|
- PGlite has one connection, so tests run claims one after another; concurrent claiming is Postgres behaviour
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export declare const jobs: import("@softure-ai/core").ModuleFactory<{}, {
|
|
|
13
13
|
not_retryable: string;
|
|
14
14
|
dedup_key_taken: string;
|
|
15
15
|
};
|
|
16
|
-
}, import("zod").ZodObject<{
|
|
17
|
-
queues: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
16
|
+
}, import("zod").ZodPipe<import("zod").ZodObject<{
|
|
17
|
+
queues: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
18
18
|
maxAttempts: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
19
19
|
backoff: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
20
20
|
baseSeconds: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
@@ -22,7 +22,11 @@ export declare const jobs: import("@softure-ai/core").ModuleFactory<{}, {
|
|
|
22
22
|
}, import("zod/v4/core").$strict>>;
|
|
23
23
|
leaseSeconds: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
24
24
|
concurrency: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
25
|
-
}, import("zod/v4/core").$strict
|
|
25
|
+
}, import("zod/v4/core").$strict>>>;
|
|
26
|
+
schedules: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodObject<{
|
|
27
|
+
every: import("zod").ZodString;
|
|
28
|
+
payload: import("zod").ZodDefault<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
29
|
+
}, import("zod/v4/core").$strict>>>;
|
|
26
30
|
pollIntervalMs: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
27
31
|
shutdownGraceMs: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
28
32
|
retention: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
@@ -30,10 +34,54 @@ export declare const jobs: import("@softure-ai/core").ModuleFactory<{}, {
|
|
|
30
34
|
failedDays: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
31
35
|
cancelledDays: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
32
36
|
}, import("zod/v4/core").$strict>>;
|
|
33
|
-
}, import("zod/v4/core").$strict
|
|
37
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodTransform<{
|
|
38
|
+
queues: {
|
|
39
|
+
[x: string]: {
|
|
40
|
+
maxAttempts: number;
|
|
41
|
+
backoff: {
|
|
42
|
+
baseSeconds: number;
|
|
43
|
+
maxSeconds: number;
|
|
44
|
+
};
|
|
45
|
+
leaseSeconds: number;
|
|
46
|
+
concurrency: number;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
schedules: Record<string, {
|
|
50
|
+
every: string;
|
|
51
|
+
payload: Record<string, unknown>;
|
|
52
|
+
}>;
|
|
53
|
+
pollIntervalMs: number;
|
|
54
|
+
shutdownGraceMs: number;
|
|
55
|
+
retention: {
|
|
56
|
+
succeededDays: number;
|
|
57
|
+
failedDays: number;
|
|
58
|
+
cancelledDays: number;
|
|
59
|
+
};
|
|
60
|
+
}, {
|
|
61
|
+
queues: Record<string, {
|
|
62
|
+
maxAttempts: number;
|
|
63
|
+
backoff: {
|
|
64
|
+
baseSeconds: number;
|
|
65
|
+
maxSeconds: number;
|
|
66
|
+
};
|
|
67
|
+
leaseSeconds: number;
|
|
68
|
+
concurrency: number;
|
|
69
|
+
}>;
|
|
70
|
+
schedules: Record<string, {
|
|
71
|
+
every: string;
|
|
72
|
+
payload: Record<string, unknown>;
|
|
73
|
+
}>;
|
|
74
|
+
pollIntervalMs: number;
|
|
75
|
+
shutdownGraceMs: number;
|
|
76
|
+
retention: {
|
|
77
|
+
succeededDays: number;
|
|
78
|
+
failedDays: number;
|
|
79
|
+
cancelledDays: number;
|
|
80
|
+
};
|
|
81
|
+
}>>>;
|
|
34
82
|
export { JOB_STATUSES, type Job, type JobFailure, type JobOutcome, type JobsErrorCode, type JobStatus, } from "./contract.js";
|
|
35
83
|
export { jobsMessages, type JobsMessages } from "./messages/index.js";
|
|
36
|
-
export { jobsOptionsSchema, type JobQueueOptions, type JobsOptions, type JobsOptionsInput } from "./options.js";
|
|
84
|
+
export { jobsOptionsSchema, type JobQueueOptions, type JobScheduleOptions, type JobSchedulesInput, type JobsOptions, type JobsOptionsInput, } from "./options.js";
|
|
37
85
|
export { defineJobHandler, failJob, retryJobLater, type JobHandler, type JobHandlerContext, type JobHandlers } from "./handlers.js";
|
|
38
|
-
export { jobs as jobsTable } from "./schema.js";
|
|
86
|
+
export { jobs as jobsTable, schedules as jobSchedulesTable } from "./schema.js";
|
|
39
87
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiBf,CAAC;AAEH,OAAO,EACL,YAAY,EACZ,KAAK,GAAG,EACR,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACpI,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,10 @@ export const MODULE_ID = "jobs";
|
|
|
13
13
|
export const jobs = defineModule({
|
|
14
14
|
manifest: {
|
|
15
15
|
id: MODULE_ID,
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.1",
|
|
17
17
|
dependsOn: {},
|
|
18
18
|
dbSchema: "jobs",
|
|
19
|
-
tables: ["jobs"],
|
|
19
|
+
tables: ["jobs", "schedules"],
|
|
20
20
|
env: [],
|
|
21
21
|
switches: [],
|
|
22
22
|
routes: {},
|
|
@@ -30,7 +30,7 @@ export const jobs = defineModule({
|
|
|
30
30
|
});
|
|
31
31
|
export { JOB_STATUSES, } from "./contract.js";
|
|
32
32
|
export { jobsMessages } from "./messages/index.js";
|
|
33
|
-
export { jobsOptionsSchema } from "./options.js";
|
|
33
|
+
export { jobsOptionsSchema, } from "./options.js";
|
|
34
34
|
export { defineJobHandler, failJob, retryJobLater } from "./handlers.js";
|
|
35
|
-
export { jobs as jobsTable } from "./schema.js";
|
|
35
|
+
export { jobs as jobsTable, schedules as jobSchedulesTable } from "./schema.js";
|
|
36
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,oHAAoH;AACpH,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,YAAY,CAAC;IAC/B,QAAQ,EAAE;QACR,EAAE,EAAE,SAAS;QACb,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,CAAC,MAAM,CAAC;
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AI,SAAS,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/** Seconds of an `every` text such as `15m`, `1h` or `1d`; null when it is not one or is outside 1m to 7d. */
|
|
3
|
+
export declare function parseEverySeconds(every: string): number | null;
|
|
4
|
+
export declare const jobsOptionsSchema: z.ZodPipe<z.ZodObject<{
|
|
5
|
+
queues: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
4
6
|
maxAttempts: z.ZodDefault<z.ZodNumber>;
|
|
5
7
|
backoff: z.ZodDefault<z.ZodObject<{
|
|
6
8
|
baseSeconds: z.ZodDefault<z.ZodNumber>;
|
|
@@ -8,7 +10,11 @@ export declare const jobsOptionsSchema: z.ZodObject<{
|
|
|
8
10
|
}, z.core.$strict>>;
|
|
9
11
|
leaseSeconds: z.ZodDefault<z.ZodNumber>;
|
|
10
12
|
concurrency: z.ZodDefault<z.ZodNumber>;
|
|
11
|
-
}, z.core.$strict
|
|
13
|
+
}, z.core.$strict>>>;
|
|
14
|
+
schedules: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
15
|
+
every: z.ZodString;
|
|
16
|
+
payload: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
17
|
+
}, z.core.$strict>>>;
|
|
12
18
|
pollIntervalMs: z.ZodDefault<z.ZodNumber>;
|
|
13
19
|
shutdownGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
14
20
|
retention: z.ZodDefault<z.ZodObject<{
|
|
@@ -16,8 +22,55 @@ export declare const jobsOptionsSchema: z.ZodObject<{
|
|
|
16
22
|
failedDays: z.ZodDefault<z.ZodNumber>;
|
|
17
23
|
cancelledDays: z.ZodDefault<z.ZodNumber>;
|
|
18
24
|
}, z.core.$strict>>;
|
|
19
|
-
}, z.core.$strict
|
|
25
|
+
}, z.core.$strict>, z.ZodTransform<{
|
|
26
|
+
queues: {
|
|
27
|
+
[x: string]: {
|
|
28
|
+
maxAttempts: number;
|
|
29
|
+
backoff: {
|
|
30
|
+
baseSeconds: number;
|
|
31
|
+
maxSeconds: number;
|
|
32
|
+
};
|
|
33
|
+
leaseSeconds: number;
|
|
34
|
+
concurrency: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
schedules: Record<string, {
|
|
38
|
+
every: string;
|
|
39
|
+
payload: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
pollIntervalMs: number;
|
|
42
|
+
shutdownGraceMs: number;
|
|
43
|
+
retention: {
|
|
44
|
+
succeededDays: number;
|
|
45
|
+
failedDays: number;
|
|
46
|
+
cancelledDays: number;
|
|
47
|
+
};
|
|
48
|
+
}, {
|
|
49
|
+
queues: Record<string, {
|
|
50
|
+
maxAttempts: number;
|
|
51
|
+
backoff: {
|
|
52
|
+
baseSeconds: number;
|
|
53
|
+
maxSeconds: number;
|
|
54
|
+
};
|
|
55
|
+
leaseSeconds: number;
|
|
56
|
+
concurrency: number;
|
|
57
|
+
}>;
|
|
58
|
+
schedules: Record<string, {
|
|
59
|
+
every: string;
|
|
60
|
+
payload: Record<string, unknown>;
|
|
61
|
+
}>;
|
|
62
|
+
pollIntervalMs: number;
|
|
63
|
+
shutdownGraceMs: number;
|
|
64
|
+
retention: {
|
|
65
|
+
succeededDays: number;
|
|
66
|
+
failedDays: number;
|
|
67
|
+
cancelledDays: number;
|
|
68
|
+
};
|
|
69
|
+
}>>;
|
|
20
70
|
export type JobsOptionsInput = z.input<typeof jobsOptionsSchema>;
|
|
21
71
|
export type JobsOptions = z.output<typeof jobsOptionsSchema>;
|
|
22
72
|
export type JobQueueOptions = JobsOptions["queues"][string];
|
|
73
|
+
export type JobScheduleOptions = JobsOptions["schedules"][string];
|
|
74
|
+
/** Schedules as an app or a package writes them, e.g. a package's ready-made prune schedules. */
|
|
75
|
+
export type JobSchedulesInput = NonNullable<JobsOptionsInput["schedules"]>;
|
|
23
76
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuBtB,8GAA8G;AAC9G,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK9D;AAgCH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwB1B,CAAC;AAQL,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5D,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,iGAAiG;AACjG,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC"}
|
package/dist/options.js
CHANGED
|
@@ -14,6 +14,24 @@ const backoffSchema = z
|
|
|
14
14
|
message: "maxSeconds must be at least baseSeconds",
|
|
15
15
|
path: ["maxSeconds"],
|
|
16
16
|
});
|
|
17
|
+
const EVERY = /^([1-9][0-9]{0,4})(m|h|d)$/;
|
|
18
|
+
const UNIT_SECONDS = { m: 60, h: 60 * 60, d: DAY_SECONDS };
|
|
19
|
+
const MAX_EVERY_SECONDS = 7 * DAY_SECONDS;
|
|
20
|
+
const EVERY_HINT = "must be a whole number of minutes, hours or days (e.g. 15m, 1h, 1d), from 1m to 7d";
|
|
21
|
+
/** Seconds of an `every` text such as `15m`, `1h` or `1d`; null when it is not one or is outside 1m to 7d. */
|
|
22
|
+
export function parseEverySeconds(every) {
|
|
23
|
+
const match = EVERY.exec(every);
|
|
24
|
+
if (match === null)
|
|
25
|
+
return null;
|
|
26
|
+
const seconds = Number(match[1]) * UNIT_SECONDS[match[2]];
|
|
27
|
+
return seconds <= MAX_EVERY_SECONDS ? seconds : null;
|
|
28
|
+
}
|
|
29
|
+
const scheduleSchema = z.strictObject({
|
|
30
|
+
/** How often the schedule runs: `15m`, `1h`, `1d`. Runs start on whole periods counted from 1970-01-01 00:00 UTC. */
|
|
31
|
+
every: z.string().refine((every) => parseEverySeconds(every) !== null, { message: EVERY_HINT }),
|
|
32
|
+
/** The payload of every run; default `{}`. */
|
|
33
|
+
payload: z.record(z.string(), z.unknown()).default({}),
|
|
34
|
+
});
|
|
17
35
|
const queueSchema = z.strictObject({
|
|
18
36
|
/** Attempts before a job is `failed` for good; the first run counts. */
|
|
19
37
|
maxAttempts: z.number().int().min(1).max(1000).default(5),
|
|
@@ -35,22 +53,34 @@ const retentionSchema = z.strictObject({
|
|
|
35
53
|
/** Days a cancelled job is kept. */
|
|
36
54
|
cancelledDays: z.number().int().min(0).max(3650).default(7),
|
|
37
55
|
});
|
|
38
|
-
export const jobsOptionsSchema = z
|
|
56
|
+
export const jobsOptionsSchema = z
|
|
57
|
+
.strictObject({
|
|
39
58
|
/** The queues, by name. A job is enqueued to one of them and runs with its settings. */
|
|
40
|
-
queues: z.record(z.string(), queueSchema).superRefine(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
context.addIssue({ code: "custom", path: [name], message: QUEUE_NAME_HINT });
|
|
47
|
-
}
|
|
48
|
-
}),
|
|
59
|
+
queues: z.record(z.string(), queueSchema).default({}).superRefine(checkNames),
|
|
60
|
+
/**
|
|
61
|
+
* Recurring runs, by queue name: the worker enqueues one job per period (`every`) however many workers run. A
|
|
62
|
+
* schedule's queue takes the default queue settings unless `queues` names it.
|
|
63
|
+
*/
|
|
64
|
+
schedules: z.record(z.string(), scheduleSchema).default({}).superRefine(checkNames),
|
|
49
65
|
/** How long an idle worker waits before it looks for due jobs again. */
|
|
50
66
|
pollIntervalMs: z.number().int().min(50).max(60_000).default(1000),
|
|
51
67
|
/** How long a stopping worker waits for running handlers before it releases their jobs. */
|
|
52
68
|
shutdownGraceMs: z.number().int().min(0).max(10 * 60_000).default(20_000),
|
|
53
69
|
/** How long finished jobs are kept; the worker prunes once an hour. */
|
|
54
70
|
retention: retentionSchema.default({ succeededDays: 7, failedDays: 30, cancelledDays: 7 }),
|
|
71
|
+
})
|
|
72
|
+
.superRefine((options, context) => {
|
|
73
|
+
if (Object.keys(options.queues).length === 0 && Object.keys(options.schedules).length === 0) {
|
|
74
|
+
context.addIssue({ code: "custom", path: ["queues"], message: "must define at least one queue or schedule" });
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.transform((options) => {
|
|
78
|
+
const scheduledOnly = Object.keys(options.schedules).filter((name) => !Object.hasOwn(options.queues, name));
|
|
79
|
+
return { ...options, queues: { ...options.queues, ...Object.fromEntries(scheduledOnly.map((name) => [name, queueSchema.parse({})])) } };
|
|
55
80
|
});
|
|
81
|
+
function checkNames(record, context) {
|
|
82
|
+
for (const name of Object.keys(record).filter((candidate) => !QUEUE_NAME.test(candidate))) {
|
|
83
|
+
context.addIssue({ code: "custom", path: [name], message: QUEUE_NAME_HINT });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
56
86
|
//# sourceMappingURL=options.js.map
|
package/dist/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],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O,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC1I,CAAC,CAAC,CAAC;AAEL,SAAS,UAAU,CAAC,MAA+B,EAAE,OAAwB;IAC3E,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;QAC1F,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -262,4 +262,96 @@ export declare const jobs: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
262
262
|
dialect: "pg";
|
|
263
263
|
}>;
|
|
264
264
|
export type JobRow = typeof jobs.$inferSelect;
|
|
265
|
+
export declare const schedules: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
266
|
+
name: "schedules";
|
|
267
|
+
schema: "jobs";
|
|
268
|
+
columns: {
|
|
269
|
+
name: import("drizzle-orm/pg-core").PgColumn<{
|
|
270
|
+
name: "name";
|
|
271
|
+
tableName: "schedules";
|
|
272
|
+
dataType: "string";
|
|
273
|
+
columnType: "PgText";
|
|
274
|
+
data: string;
|
|
275
|
+
driverParam: string;
|
|
276
|
+
notNull: true;
|
|
277
|
+
hasDefault: false;
|
|
278
|
+
isPrimaryKey: true;
|
|
279
|
+
isAutoincrement: false;
|
|
280
|
+
hasRuntimeDefault: false;
|
|
281
|
+
enumValues: [string, ...string[]];
|
|
282
|
+
baseColumn: never;
|
|
283
|
+
identity: undefined;
|
|
284
|
+
generated: undefined;
|
|
285
|
+
}, {}, {}>;
|
|
286
|
+
lastSlotAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
287
|
+
name: "last_slot_at";
|
|
288
|
+
tableName: "schedules";
|
|
289
|
+
dataType: "date";
|
|
290
|
+
columnType: "PgTimestamp";
|
|
291
|
+
data: Date;
|
|
292
|
+
driverParam: string;
|
|
293
|
+
notNull: true;
|
|
294
|
+
hasDefault: false;
|
|
295
|
+
isPrimaryKey: false;
|
|
296
|
+
isAutoincrement: false;
|
|
297
|
+
hasRuntimeDefault: false;
|
|
298
|
+
enumValues: undefined;
|
|
299
|
+
baseColumn: never;
|
|
300
|
+
identity: undefined;
|
|
301
|
+
generated: undefined;
|
|
302
|
+
}, {}, {}>;
|
|
303
|
+
lastSucceededAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
304
|
+
name: "last_succeeded_at";
|
|
305
|
+
tableName: "schedules";
|
|
306
|
+
dataType: "date";
|
|
307
|
+
columnType: "PgTimestamp";
|
|
308
|
+
data: Date;
|
|
309
|
+
driverParam: string;
|
|
310
|
+
notNull: false;
|
|
311
|
+
hasDefault: false;
|
|
312
|
+
isPrimaryKey: false;
|
|
313
|
+
isAutoincrement: false;
|
|
314
|
+
hasRuntimeDefault: false;
|
|
315
|
+
enumValues: undefined;
|
|
316
|
+
baseColumn: never;
|
|
317
|
+
identity: undefined;
|
|
318
|
+
generated: undefined;
|
|
319
|
+
}, {}, {}>;
|
|
320
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
321
|
+
name: "created_at";
|
|
322
|
+
tableName: "schedules";
|
|
323
|
+
dataType: "date";
|
|
324
|
+
columnType: "PgTimestamp";
|
|
325
|
+
data: Date;
|
|
326
|
+
driverParam: string;
|
|
327
|
+
notNull: true;
|
|
328
|
+
hasDefault: false;
|
|
329
|
+
isPrimaryKey: false;
|
|
330
|
+
isAutoincrement: false;
|
|
331
|
+
hasRuntimeDefault: false;
|
|
332
|
+
enumValues: undefined;
|
|
333
|
+
baseColumn: never;
|
|
334
|
+
identity: undefined;
|
|
335
|
+
generated: undefined;
|
|
336
|
+
}, {}, {}>;
|
|
337
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
338
|
+
name: "updated_at";
|
|
339
|
+
tableName: "schedules";
|
|
340
|
+
dataType: "date";
|
|
341
|
+
columnType: "PgTimestamp";
|
|
342
|
+
data: Date;
|
|
343
|
+
driverParam: string;
|
|
344
|
+
notNull: true;
|
|
345
|
+
hasDefault: false;
|
|
346
|
+
isPrimaryKey: false;
|
|
347
|
+
isAutoincrement: false;
|
|
348
|
+
hasRuntimeDefault: false;
|
|
349
|
+
enumValues: undefined;
|
|
350
|
+
baseColumn: never;
|
|
351
|
+
identity: undefined;
|
|
352
|
+
generated: undefined;
|
|
353
|
+
}, {}, {}>;
|
|
354
|
+
};
|
|
355
|
+
dialect: "pg";
|
|
356
|
+
}>;
|
|
265
357
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,gDAAmB,CAAC;AAE3C,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBf,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,gDAAmB,CAAC;AAE3C,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBf,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,YAAY,CAAC;AAE9C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMpB,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Drizzle view of the module's
|
|
1
|
+
// Drizzle view of the module's tables (migrations/). The migrations are the source of truth; this
|
|
2
2
|
// file only types the queries.
|
|
3
3
|
import { bigint, integer, jsonb, pgSchema, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
4
4
|
export const jobsSchema = pgSchema("jobs");
|
|
@@ -19,4 +19,11 @@ export const jobs = jobsSchema.table("jobs", {
|
|
|
19
19
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
20
20
|
finishedAt: timestamp("finished_at", { withTimezone: true }),
|
|
21
21
|
});
|
|
22
|
+
export const schedules = jobsSchema.table("schedules", {
|
|
23
|
+
name: text("name").primaryKey(),
|
|
24
|
+
lastSlotAt: timestamp("last_slot_at", { withTimezone: true }).notNull(),
|
|
25
|
+
lastSucceededAt: timestamp("last_succeeded_at", { withTimezone: true }),
|
|
26
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
27
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
28
|
+
});
|
|
22
29
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,+BAA+B;AAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE9F,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE;IAC3C,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,yBAAyB,EAAE;IAC7E,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACnC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;IACtG,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACvC,WAAW,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAC9C,KAAK,E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claimJobs(ctx: JobsContext, input: ClaimJobsInput): Promise<ClaimedJob[]>;
|
|
33
33
|
/** Pushes the lease of a held job forward. False when the job is no longer this claim's: stop working on it. */
|
|
34
34
|
export declare function extendJobLease(ctx: JobsContext, claimed: ClaimedJob): Promise<boolean>;
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Records the end of an attempt; a success of a scheduled queue also updates its schedule, in the same transaction.
|
|
37
|
+
* False when the job is no longer this claim's: nothing was written.
|
|
38
|
+
*/
|
|
36
39
|
export declare function completeJob(ctx: JobsContext, claimed: ClaimedJob, completion: Completion): Promise<boolean>;
|
|
37
40
|
/**
|
|
38
41
|
* Gives a held job back without an outcome (the worker is stopping): pending again, due now, and the attempt is not
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../src/server/claim.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../src/server/claim.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhD,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,uCAAuC;AACvC,MAAM,MAAM,UAAU,GAClB;IAA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