@shivaedev/effect-pg-boss 0.10.1 → 0.12.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 +19 -0
- package/README.md +51 -4
- package/dist/server/definition.d.ts +59 -25
- package/dist/server/definition.d.ts.map +1 -1
- package/dist/server/definition.js +25 -27
- package/dist/server/definition.js.map +1 -1
- package/dist/server/internal/batchHandler.d.ts.map +1 -1
- package/dist/server/internal/batchHandler.js +13 -7
- package/dist/server/internal/batchHandler.js.map +1 -1
- package/dist/server/internal/deferrableAttempt.d.ts +7 -0
- package/dist/server/internal/deferrableAttempt.d.ts.map +1 -0
- package/dist/server/internal/deferrableAttempt.js +28 -0
- package/dist/server/internal/deferrableAttempt.js.map +1 -0
- package/dist/server/internal/deferral.d.ts +15 -0
- package/dist/server/internal/deferral.d.ts.map +1 -0
- package/dist/server/internal/deferral.js +14 -0
- package/dist/server/internal/deferral.js.map +1 -0
- package/dist/server/internal/deferralStorePlan.d.ts +2 -0
- package/dist/server/internal/deferralStorePlan.d.ts.map +1 -0
- package/dist/server/internal/deferralStorePlan.js +34 -0
- package/dist/server/internal/deferralStorePlan.js.map +1 -0
- package/dist/server/internal/definitionOptions.d.ts +17 -0
- package/dist/server/internal/definitionOptions.d.ts.map +1 -0
- package/dist/server/internal/definitionOptions.js +12 -0
- package/dist/server/internal/definitionOptions.js.map +1 -0
- package/dist/server/internal/expireAttempt.d.ts +1 -1
- package/dist/server/internal/expireAttempt.d.ts.map +1 -1
- package/dist/server/internal/expireAttempt.js +4 -2
- package/dist/server/internal/expireAttempt.js.map +1 -1
- package/dist/server/internal/lifecycle.d.ts.map +1 -1
- package/dist/server/internal/lifecycle.js +4 -0
- package/dist/server/internal/lifecycle.js.map +1 -1
- package/dist/server/internal/register.d.ts +1 -1
- package/dist/server/internal/register.d.ts.map +1 -1
- package/dist/server/internal/register.js +10 -10
- package/dist/server/internal/register.js.map +1 -1
- package/dist/server/internal/registerWorker.d.ts +2 -2
- package/dist/server/internal/registerWorker.d.ts.map +1 -1
- package/dist/server/internal/registerWorker.js +7 -2
- package/dist/server/internal/registerWorker.js.map +1 -1
- package/dist/server/internal/scheduleDefinition.d.ts +3 -0
- package/dist/server/internal/scheduleDefinition.d.ts.map +1 -0
- package/dist/server/internal/scheduleDefinition.js +19 -0
- package/dist/server/internal/scheduleDefinition.js.map +1 -0
- package/dist/server/internal/service.js +1 -1
- package/dist/server/internal/service.js.map +1 -1
- package/dist/server/internal/settleDeferral.d.ts +7 -0
- package/dist/server/internal/settleDeferral.d.ts.map +1 -0
- package/dist/server/internal/settleDeferral.js +47 -0
- package/dist/server/internal/settleDeferral.js.map +1 -0
- package/dist/server/internal/testingClient.d.ts.map +1 -1
- package/dist/server/internal/testingClient.js +4 -1
- package/dist/server/internal/testingClient.js.map +1 -1
- package/dist/server/internal/testingDeferrals.d.ts +11 -0
- package/dist/server/internal/testingDeferrals.d.ts.map +1 -0
- package/dist/server/internal/testingDeferrals.js +28 -0
- package/dist/server/internal/testingDeferrals.js.map +1 -0
- package/dist/server/schema.d.ts.map +1 -1
- package/dist/server/schema.js +8 -1
- package/dist/server/schema.js.map +1 -1
- package/dist/server/service.d.ts +5 -3
- package/dist/server/service.d.ts.map +1 -1
- package/dist/server/service.js +1 -1
- package/dist/server/service.js.map +1 -1
- package/dist/server/testing.d.ts +8 -3
- package/dist/server/testing.d.ts.map +1 -1
- package/dist/server/testing.js +4 -0
- package/dist/server/testing.js.map +1 -1
- package/package.json +5 -5
- package/src/server/definition.ts +75 -58
- package/src/server/internal/batchHandler.ts +21 -6
- package/src/server/internal/deferrableAttempt.ts +41 -0
- package/src/server/internal/deferral.ts +19 -0
- package/src/server/internal/deferralStorePlan.ts +34 -0
- package/src/server/internal/definitionOptions.ts +14 -0
- package/src/server/internal/expireAttempt.ts +4 -2
- package/src/server/internal/lifecycle.ts +4 -0
- package/src/server/internal/register.ts +15 -15
- package/src/server/internal/registerWorker.ts +39 -26
- package/src/server/internal/scheduleDefinition.ts +21 -0
- package/src/server/internal/service.ts +1 -1
- package/src/server/internal/settleDeferral.ts +53 -0
- package/src/server/internal/testingClient.ts +4 -1
- package/src/server/internal/testingDeferrals.ts +43 -0
- package/src/server/schema.ts +8 -1
- package/src/server/service.ts +7 -7
- package/src/server/testing.ts +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0 - 2026-10-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Export `QueuePolicy` as the pinned pg-boss policy literals. Singleton queue definitions require `key: (payload) => string`, evaluated from the decoded payload when enqueueing. Related tagged-union job kinds can share one entity key: PostgreSQL allows one active job per key, other keys can run in parallel, and jobs waiting to retry or sent to the dead-letter queue leave the key available. Singleton does not guarantee ordering; applications keep handlers idempotent and guard writes against stale sources.
|
|
8
|
+
|
|
9
|
+
### Breaking
|
|
10
|
+
|
|
11
|
+
- `defineQueue` rejects unknown policy strings and requires `key` for `queue.policy: "singleton"`. Move per-job `singletonKey` options into the queue definition's key callback and remove them from `enqueue` calls for singleton queues. Ordinary queues retain native send options. Let `enqueue` infer its type arguments, or supply the queue-definition type as its third type argument in explicit generic calls.
|
|
12
|
+
|
|
13
|
+
## 0.11.0 - 2026-10-18
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Fail a queue or scheduled handler with `RetryAt({ at, reason })` from `definition.ts` to defer the same job until a UTC time without spending a retry, changing its payload or singleton key, or calling `onError`. A deferred attempt ends its span OK with a `job.deferred` event. The exported `QueueOptions` type adds `maxDeferrals`, and queue and schedule definitions expose its resolved value. `queue.maxDeferrals` defaults to 10 per job; subsequent deferrals fail normally. Deferred jobs use the polling backstop, including with `notify: true`.
|
|
18
|
+
- Inspect waiting deferrals with the testing controller's `deferred(queue)`, returning `{ at, reason }[]`, and pull them forward with `runDeferredNow(queue)`. Both integrate with the controller's revision and change notification controls.
|
|
19
|
+
- Deferral counts survive native expiry and heartbeat failures. Automatic migrations and `installPgBossSchema` install the adapter's durable counter table alongside the pg-boss schema.
|
|
20
|
+
- Stately jobs sharing a singleton key can defer together without colliding or spending retries, and resume one at a time. Waiting deferrals use the `effect-stately-deferred` policy in native job metadata; an adapter-installed database trigger restores `stately` when claimed.
|
|
21
|
+
|
|
3
22
|
## 0.10.1 - 2026-10-18
|
|
4
23
|
|
|
5
24
|
### Fixed
|
package/README.md
CHANGED
|
@@ -130,6 +130,51 @@ This worker runs up to five handlers at once. `worker` accepts pg-boss 12's `Wor
|
|
|
130
130
|
|
|
131
131
|
Apps do not need to shorten the polling backstop to drain a backlog. With `notify: true` and an active LISTEN/NOTIFY listener, pg-boss wakes workers on notifications and defaults to a 30-second backstop (`notifyPollingIntervalSeconds`). Without active notifications its base poll defaults to two seconds (`pollingIntervalSeconds`). Bursting takes precedence over both intervals. After an adapter worker fails a job, it reads pg-boss's stored retry time and schedules a wake for every native worker in its registration at that time, so an idle sibling can retry while another worker is busy. The wake belongs to the worker Layer's scope and is canceled when that scope closes. Override the backstop when the application needs a different bound for other work that becomes runnable without a notification, such as delayed jobs or retries initiated outside the adapter worker.
|
|
132
132
|
|
|
133
|
+
### Defer until a provider is ready
|
|
134
|
+
|
|
135
|
+
Fail a queue handler or scheduled Effect with `RetryAt` when a provider gives a time to try again:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { DateTime, Effect } from "effect";
|
|
139
|
+
import { RetryAt } from "@shivaedev/effect-pg-boss/definition.ts";
|
|
140
|
+
|
|
141
|
+
const waitForQuota = Effect.fail(new RetryAt({
|
|
142
|
+
at: DateTime.makeUnsafe("2030-01-01T00:01:00Z"),
|
|
143
|
+
reason: "Provider quota resets",
|
|
144
|
+
}));
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The same job returns to waiting with `startAfter` set to `at`; its ID, singleton key, payload and retry count stay unchanged. A past or current `at` is eligible on the next fetch. Deferral does not dead-letter the job or call `onError`. Its job span ends OK with a `job.deferred` event whose `at` is an ISO UTC string and whose `reason` is the supplied string. Deferred jobs rely on polling, including queues using `notify: true`. Stately jobs sharing a singleton key can defer together and still run one at a time. While waiting, their native job metadata reports the adapter's `effect-stately-deferred` policy; a database trigger restores `stately` when pg-boss claims them, preserving its active-job exclusion.
|
|
148
|
+
|
|
149
|
+
Set `queue: { maxDeferrals: 20 }` on a queue or schedule to change the default limit of ten deferrals per job. The limit must be a nonnegative safe integer; zero disables deferral. Once the limit is reached, `RetryAt` follows the normal failure and retry path. The adapter stores the count in its own table in the pg-boss schema, preserving it across worker restarts, ordinary failures, expiry and heartbeat timeouts. Automatic migrations and `installPgBossSchema` create this table and the stately claim trigger; use `installPgBossSchema` before starting workers with `migrate: false`.
|
|
150
|
+
|
|
151
|
+
### One active job per entity
|
|
152
|
+
|
|
153
|
+
Put related job kinds in one tagged-union queue and choose the entity key in the definition:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
const PullRequestJobs = defineQueue({
|
|
157
|
+
name: "pull-request",
|
|
158
|
+
schema: Schema.Union([
|
|
159
|
+
Schema.TaggedStruct("Refresh", { pullRequestId: Schema.NumberFromString }),
|
|
160
|
+
Schema.TaggedStruct("Reconcile", { pullRequestId: Schema.NumberFromString }),
|
|
161
|
+
]),
|
|
162
|
+
queue: { policy: "singleton" },
|
|
163
|
+
key: ({ pullRequestId }) => `pr:${pullRequestId.toFixed(0)}`,
|
|
164
|
+
worker: { batchSize: 1, localConcurrency: 3 },
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const refresh = Effect.flatMap(Jobs, (jobs) =>
|
|
168
|
+
jobs.enqueue(PullRequestJobs, { _tag: "Refresh", pullRequestId: 42 }),
|
|
169
|
+
);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`queue.policy` accepts pg-boss's policy literals and rejects typos. The `singleton` policy requires `key: (payload) => string`. The callback sees the decoded payload, so `pullRequestId` is a number. `enqueue` supplies pg-boss's `singletonKey` automatically; callers cannot supply a conflicting key in send options.
|
|
173
|
+
|
|
174
|
+
PostgreSQL guarantees one active job per key across workers, including different job kinds in this queue. Different keys can run in parallel when workers have capacity. A job waiting to retry frees its key for another job; exhausting retries sends it to the dead-letter queue and leaves the key available.
|
|
175
|
+
|
|
176
|
+
Singleton guarantees one active job per key, not order. Ordering stays the application's job. Keep handlers idempotent and write state only when the source is newer than what is stored, so an older event or retry cannot overwrite newer state.
|
|
177
|
+
|
|
133
178
|
### Size batches against expiry
|
|
134
179
|
|
|
135
180
|
pg-boss marks every job in a fetched batch active together. Each job's expiry window starts at its stored `startedOn`, including time waiting for earlier handlers. Size each queue's batch so its sequential work fits within that window; use a small batch for long-running work and keep the default for short work:
|
|
@@ -275,7 +320,7 @@ export const inspectEmail = (id: string) => Effect.gen(function* () {
|
|
|
275
320
|
|
|
276
321
|
### Queue settings on startup
|
|
277
322
|
|
|
278
|
-
`queue` accepts pg-boss `Queue` options except `name` and `deadLetter`, which the definition and adapter own. For prompt delivery, set `queue: { notify: true }` and enable `useListenNotify: true` in the worker Layer's constructor options.
|
|
323
|
+
`queue` accepts pg-boss `Queue` options except `name` and `deadLetter`, which the definition and adapter own, plus the adapter’s `maxDeferrals` limit. For prompt delivery, set `queue: { notify: true }` and enable `useListenNotify: true` in the worker Layer's constructor options.
|
|
279
324
|
|
|
280
325
|
Startup creates missing queues and reconciles declared settings on existing queues through `updateQueue`. Unspecified settings keep their stored values; the adapter always supplies its default retry settings and dead-letter destination. Changing an explicitly declared `policy` or `partition` on an existing queue fails startup with `PgBossQueueOptionsError`; its `queue`, `options` and message identify the conflict. Queue setting changes apply to subsequently enqueued jobs. Schedule queues follow the same registration path.
|
|
281
326
|
|
|
@@ -381,6 +426,8 @@ Set `retryPolicy: testRetryPolicy` through the controller to override queue and
|
|
|
381
426
|
|
|
382
427
|
`failNextSend(queue)` arms one send failure for that queue. The next valid `enqueue` fails with the usual typed `PgBossError` (`operation: "enqueue"`); the following send proceeds normally. `expireAfter(queue, n)` takes a positive attempt count: configure it before enqueueing to limit subsequent jobs to `n` attempts. Each successful send keeps its own expiry rule; later changes and duplicate-ID sends do not alter pending jobs. Earlier attempts run the handler normally; on attempt `n`, the controller expires the claimed job instead of invoking its handler. PostgreSQL supervision performs the terminal failure and dead lettering. A job that succeeds earlier completes normally. This expiry hook supports pg-boss schema version 45.
|
|
383
428
|
|
|
429
|
+
`deferred(queue)` returns waiting deferrals as `{ at: DateTime.Utc, reason: string }[]`. `runDeferredNow(queue)` pulls those jobs forward to the database’s current time and wakes local workers without waiting for their original due time. Read `revision` before reading deferrals and use `waitForChange(revision)` as with other controls.
|
|
430
|
+
|
|
384
431
|
`checkBatchWindow(queue, millisecondsPerJob)` checks that the declared sequential batch fits strictly inside the stored queue expiry window. `schemaVersion` reads the installed version, and `checkSchemaVersion(expected)` fails when it differs. Test control, read and check failures use `PgBossTestingError` with `operation`, optional `queue` and a redacted `original`.
|
|
385
432
|
|
|
386
433
|
A kit can capture `revision` before reading jobs and yield `waitForChange(revision)` when its condition is unmet. The wait resumes after a local send, settlement, worker fetch or return to idle, including terminal native worker timeouts whose handler promises remain pending. It also resumes immediately if a change occurred between the read and the wait. This signal observes the controller's client; external clients, future scheduled work and external database writes need their own wake source. Stories should retain a bounded test timeout.
|
|
@@ -391,7 +438,7 @@ Import the module that defines the name; the package has no root entry.
|
|
|
391
438
|
|
|
392
439
|
| Module | Public names |
|
|
393
440
|
| --- | --- |
|
|
394
|
-
| `@shivaedev/effect-pg-boss/definition.ts` | `defineQueue`, `defineSchedule`, `jobContext`; `DefineQueueOptions`, `DefineScheduleOptions`, `JobContext`, `JobPayloadSchema`, `JobRegistration`, `QueueDefinition`, `QueueWorker`, `RegistrationRequirements`, `ScheduleDefinition`, `ScheduledWorker` |
|
|
441
|
+
| `@shivaedev/effect-pg-boss/definition.ts` | `defineQueue`, `defineSchedule`, `jobContext`, `RetryAt`; `DefineQueueOptions`, `DefineScheduleOptions`, `JobContext`, `JobPayloadSchema`, `JobRegistration`, `QueueDefinition`, `QueueOptions`, `QueuePolicy`, `QueueWorker`, `RegistrationRequirements`, `ScheduleDefinition`, `ScheduledWorker` |
|
|
395
442
|
| `@shivaedev/effect-pg-boss/service.ts` | `makePgBoss`; `PgBossDefinition`, `PgBossLayerOptions`, `PgBossService` |
|
|
396
443
|
| `@shivaedev/effect-pg-boss/schema.ts` | `installPgBossSchema`; `PgBossSchemaOptions` |
|
|
397
444
|
| `@shivaedev/effect-pg-boss/health.ts` | `deadLetterQueueName`; `JobsHealth`, `QueueCounts`, `QueueHealth` |
|
|
@@ -399,9 +446,9 @@ Import the module that defines the name; the package has no root entry.
|
|
|
399
446
|
| `@shivaedev/effect-pg-boss/client.ts` | `defaultClientFactory`; `PgBossClient`, `PgBossClientFactory` |
|
|
400
447
|
| `@shivaedev/effect-pg-boss/testing.ts` | `makePgBossTesting`, `testRetryPolicy`; `PgBossTesting`, `PgBossTestingOptions` |
|
|
401
448
|
|
|
402
|
-
The definition options keep the pg-boss names: `queue` uses `Queue` except `name` and `deadLetter`, `worker` uses `WorkOptions`, and a schedule's `schedule` uses `ScheduleOptions`. A queue also requires `name` and `schema`; a schedule requires `name` and `cron`.
|
|
449
|
+
The definition options keep the pg-boss names: `queue` uses `QueueOptions` (`Queue` except `name` and `deadLetter`, with literal `QueuePolicy` values and `maxDeferrals`), `worker` uses `WorkOptions`, and a schedule's `schedule` uses `ScheduleOptions`. A queue also requires `name` and `schema`; a schedule requires `name` and `cron`.
|
|
403
450
|
|
|
404
|
-
`Jobs.layer(options)` accepts pg-boss `ConstructorOptions` plus the adapter's own options. Custom clients must supply native `complete` and `fail` capabilities to register queue or schedule workers; missing settlement capabilities fail Layer acquisition with a registration `PgBossError`. Producer-only clients do not need them. Custom clients can also supply the optional native capabilities `findJobs`, `retry`, `update`, `getDb` and `updateQueue` for lookup, retry, live counts and reconciliation; a requested operation fails with `PgBossError` if its required capability is absent.
|
|
451
|
+
`Jobs.layer(options)` accepts pg-boss `ConstructorOptions` plus the adapter's own options. Custom clients must supply native `complete` and `fail` capabilities to register queue or schedule workers; missing settlement capabilities fail Layer acquisition with a registration `PgBossError`. Producer-only clients do not need them. Custom clients can also supply the optional native capabilities `findJobs`, `retry`, `update`, `getDb` and `updateQueue` for lookup, retry, live counts, deferral and reconciliation; a requested operation fails with `PgBossError` if its required capability is absent.
|
|
405
452
|
|
|
406
453
|
`onError` handles pg-boss client `error` events using the services captured by the Layer. Only the owning jobs service is supplied automatically; a handler using another jobs definition still requires that definition's Layer.
|
|
407
454
|
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { Duration, Effect,
|
|
2
|
-
import type { Job, Queue, ScheduleOptions, WorkOptions } from "pg-boss";
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import type { Job, policies, Queue, ScheduleOptions, WorkOptions } from "pg-boss";
|
|
3
|
+
declare const RetryAt_base: Schema.Class<RetryAt, Schema.TaggedStruct<"RetryAt", {
|
|
4
|
+
readonly at: Schema.DateTimeUtc;
|
|
5
|
+
readonly reason: Schema.String;
|
|
6
|
+
}>, import("effect/Cause").YieldableError>;
|
|
7
|
+
export declare class RetryAt extends RetryAt_base {
|
|
8
|
+
}
|
|
9
|
+
export type QueuePolicy = (typeof policies)[keyof typeof policies];
|
|
10
|
+
export type QueueOptions = Omit<Queue, "name" | "deadLetter" | "policy"> & {
|
|
11
|
+
readonly maxDeferrals?: number;
|
|
12
|
+
readonly policy?: QueuePolicy;
|
|
13
|
+
};
|
|
3
14
|
export interface JobPayloadSchema extends Schema.Top {
|
|
4
15
|
readonly Encoded: object;
|
|
5
16
|
readonly Type: object;
|
|
@@ -12,51 +23,74 @@ export interface JobContext {
|
|
|
12
23
|
readonly remainingBudget: Effect.Effect<Duration.Duration>;
|
|
13
24
|
readonly signal: AbortSignal;
|
|
14
25
|
}
|
|
15
|
-
export interface QueueDefinition<
|
|
26
|
+
export interface QueueDefinition<TName extends string = string, TPayload extends JobPayloadSchema = JobPayloadSchema> {
|
|
16
27
|
readonly _tag: "QueueDefinition";
|
|
17
|
-
readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<
|
|
18
|
-
readonly
|
|
28
|
+
readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<TPayload>, job: JobContext) => Effect.Effect<unknown, E, R>) => QueueWorker<TPayload, R>;
|
|
29
|
+
readonly key?: ((payload: Schema.Schema.Type<TPayload>) => string) | undefined;
|
|
30
|
+
readonly maxDeferrals: number;
|
|
31
|
+
readonly name: TName;
|
|
19
32
|
readonly queueOptions: Omit<Queue, "name" | "deadLetter">;
|
|
20
|
-
readonly schema:
|
|
33
|
+
readonly schema: TPayload;
|
|
21
34
|
readonly workerOptions: WorkOptions;
|
|
22
35
|
}
|
|
23
|
-
export interface QueueWorker<
|
|
36
|
+
export interface QueueWorker<TPayload extends JobPayloadSchema = JobPayloadSchema, TRequirements = unknown> {
|
|
24
37
|
readonly _tag: "QueueWorker";
|
|
25
|
-
readonly handler: (payload: Schema.Schema.Type<
|
|
26
|
-
readonly queue: QueueDefinition<string,
|
|
38
|
+
readonly handler: (payload: Schema.Schema.Type<TPayload>, job: JobContext) => Effect.Effect<unknown, unknown, TRequirements>;
|
|
39
|
+
readonly queue: QueueDefinition<string, TPayload>;
|
|
27
40
|
}
|
|
28
41
|
export interface JobRegistration {
|
|
29
42
|
readonly _tag: "QueueDefinition" | "QueueWorker" | "ScheduledWorker";
|
|
30
43
|
}
|
|
31
|
-
export interface ScheduleDefinition<
|
|
44
|
+
export interface ScheduleDefinition<TName extends string = string> {
|
|
32
45
|
readonly _tag: "ScheduleDefinition";
|
|
33
46
|
readonly cron: string;
|
|
34
|
-
readonly
|
|
47
|
+
readonly maxDeferrals: number;
|
|
48
|
+
readonly name: TName;
|
|
35
49
|
readonly queueOptions: Omit<Queue, "name" | "deadLetter">;
|
|
36
50
|
readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
|
|
37
51
|
readonly scheduleOptions: ScheduleOptions;
|
|
38
52
|
readonly workerOptions: WorkOptions;
|
|
39
53
|
}
|
|
40
|
-
export interface ScheduledWorker<
|
|
54
|
+
export interface ScheduledWorker<TRequirements = unknown> {
|
|
41
55
|
readonly _tag: "ScheduledWorker";
|
|
42
|
-
readonly effect: Effect.Effect<unknown, unknown,
|
|
56
|
+
readonly effect: Effect.Effect<unknown, unknown, TRequirements>;
|
|
43
57
|
readonly schedule: ScheduleDefinition;
|
|
44
58
|
}
|
|
45
|
-
export type RegistrationRequirements<
|
|
46
|
-
export
|
|
47
|
-
readonly name:
|
|
48
|
-
readonly
|
|
49
|
-
readonly schema: Payload;
|
|
59
|
+
export type RegistrationRequirements<TRegistrations extends readonly JobRegistration[]> = TRegistrations[number] extends infer TRegistration ? TRegistration extends QueueWorker<infer TPayload, infer TRequirements> ? TRequirements | TPayload["DecodingServices"] : TRegistration extends ScheduledWorker<infer TRequirements> ? TRequirements : never : never;
|
|
60
|
+
export type DefineQueueOptions<TName extends string, TPayload extends JobPayloadSchema> = {
|
|
61
|
+
readonly name: TName;
|
|
62
|
+
readonly schema: TPayload;
|
|
50
63
|
readonly worker?: WorkOptions;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
} & ({
|
|
65
|
+
readonly key: (payload: Schema.Schema.Type<TPayload>) => string;
|
|
66
|
+
readonly queue: QueueOptions & {
|
|
67
|
+
readonly policy: "singleton";
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
readonly key?: never;
|
|
71
|
+
readonly queue?: QueueOptions & {
|
|
72
|
+
readonly policy?: Exclude<QueuePolicy, "singleton">;
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
export declare function defineQueue<const TName extends string, const TPayload extends JobPayloadSchema>(options: DefineQueueOptions<TName, TPayload> & {
|
|
76
|
+
readonly key: (payload: Schema.Schema.Type<TPayload>) => string;
|
|
77
|
+
}): QueueDefinition<TName, TPayload> & {
|
|
78
|
+
readonly key: (payload: Schema.Schema.Type<TPayload>) => string;
|
|
79
|
+
};
|
|
80
|
+
export declare function defineQueue<const TName extends string, const TPayload extends JobPayloadSchema>(options: DefineQueueOptions<TName, TPayload> & {
|
|
81
|
+
readonly key?: never;
|
|
82
|
+
}): QueueDefinition<TName, TPayload> & {
|
|
83
|
+
readonly key?: never;
|
|
84
|
+
};
|
|
85
|
+
export declare function defineQueue<const TName extends string, const TPayload extends JobPayloadSchema>(options: DefineQueueOptions<TName, TPayload>): QueueDefinition<TName, TPayload>;
|
|
86
|
+
export interface DefineScheduleOptions<TName extends string> {
|
|
54
87
|
readonly cron: string;
|
|
55
|
-
readonly name:
|
|
56
|
-
readonly queue?:
|
|
88
|
+
readonly name: TName;
|
|
89
|
+
readonly queue?: QueueOptions;
|
|
57
90
|
readonly schedule?: ScheduleOptions;
|
|
58
91
|
readonly worker?: WorkOptions;
|
|
59
92
|
}
|
|
60
|
-
export declare
|
|
61
|
-
export declare
|
|
93
|
+
export declare function defineSchedule<const TName extends string>(options: DefineScheduleOptions<TName>): ScheduleDefinition<TName>;
|
|
94
|
+
export declare function jobContext(job: Job<unknown>): JobContext;
|
|
95
|
+
export {};
|
|
62
96
|
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/server/definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/server/definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;;;;;AAKlF,qBAAa,OAAQ,SAAQ,YAG3B;CAAG;AAEL,MAAM,MAAM,WA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,EAAE,QAAQ,CAAC,CAAC;AAsBpC,MAAM,WAAW,qBAAqB,CAAC,KAAK,SAAS,MAAM;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED,wBAAgB,cAAc,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAE3H;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,UAAU,CASxD"}
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
import { Clock, Duration, Effect } from "effect";
|
|
1
|
+
import { Clock, Duration, Effect, Schema } from "effect";
|
|
2
2
|
import { deadlineOf } from "#internal/deadlineOf.ts";
|
|
3
|
-
|
|
3
|
+
import { maxDeferrals, nativeQueueOptions } from "#internal/definitionOptions.ts";
|
|
4
|
+
import { scheduleDefinition } from "#internal/scheduleDefinition.ts";
|
|
5
|
+
export class RetryAt extends Schema.TaggedError()("RetryAt", {
|
|
6
|
+
at: Schema.DateTimeUtc,
|
|
7
|
+
reason: Schema.String,
|
|
8
|
+
}) {
|
|
9
|
+
}
|
|
10
|
+
export function defineQueue(options) {
|
|
4
11
|
const definition = {
|
|
5
12
|
_tag: "QueueDefinition",
|
|
13
|
+
...(options.key === undefined ? {} : { key: options.key }),
|
|
6
14
|
handle: (handler) => Object.freeze({
|
|
7
15
|
_tag: "QueueWorker",
|
|
8
16
|
handler,
|
|
9
17
|
queue: definition,
|
|
10
18
|
}),
|
|
19
|
+
maxDeferrals: maxDeferrals(options.queue),
|
|
11
20
|
name: options.name,
|
|
12
|
-
queueOptions:
|
|
21
|
+
queueOptions: nativeQueueOptions(options.queue),
|
|
13
22
|
schema: options.schema,
|
|
14
23
|
workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
|
|
15
24
|
};
|
|
16
25
|
return Object.freeze(definition);
|
|
17
|
-
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
|
|
30
|
-
workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
|
|
26
|
+
}
|
|
27
|
+
export function defineSchedule(options) {
|
|
28
|
+
return scheduleDefinition(options);
|
|
29
|
+
}
|
|
30
|
+
export function jobContext(job) {
|
|
31
|
+
return {
|
|
32
|
+
expireInSeconds: job.expireInSeconds,
|
|
33
|
+
heartbeatSeconds: job.heartbeatSeconds,
|
|
34
|
+
id: job.id,
|
|
35
|
+
name: job.name,
|
|
36
|
+
remainingBudget: Effect.map(Clock.currentTimeMillis, (now) => Duration.millis(Math.max(0, deadlineOf(job) - now))),
|
|
37
|
+
signal: job.signal,
|
|
31
38
|
};
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
export const jobContext = (job) => ({
|
|
35
|
-
expireInSeconds: job.expireInSeconds,
|
|
36
|
-
heartbeatSeconds: job.heartbeatSeconds,
|
|
37
|
-
id: job.id,
|
|
38
|
-
name: job.name,
|
|
39
|
-
remainingBudget: Effect.map(Clock.currentTimeMillis, (now) => Duration.millis(Math.max(0, deadlineOf(job) - now))),
|
|
40
|
-
signal: job.signal,
|
|
41
|
-
});
|
|
39
|
+
}
|
|
42
40
|
//# sourceMappingURL=definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/server/definition.ts"],"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C,MAAM,EAAE,CAAC;KAC5F,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC;AAUD,MAAM,UAAU,cAAc,CAA6B,OAAqC;IAC/F,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAiB;IAC3C,OAAO;QACN,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;QACtC,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAClH,MAAM,EAAE,GAAG,CAAC,MAAM;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchHandler.d.ts","sourceRoot":"","sources":["../../../src/server/internal/batchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAQ,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"batchHandler.d.ts","sourceRoot":"","sources":["../../../src/server/internal/batchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAQ,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA2B/C,wBAAgB,YAAY,CAC3B,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EAC3D,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,UAQ/B,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAyB3D"}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { Cause, Clock, Effect, Exit } from "effect";
|
|
2
2
|
import { deadlineOf } from "#internal/deadlineOf.ts";
|
|
3
|
+
import { deferredAttempt } from "#internal/deferral.ts";
|
|
3
4
|
function failureOutput(cause) {
|
|
4
5
|
const error = Cause.squash(cause);
|
|
5
6
|
return typeof error === "object" && error !== null ? error : { message: String(error) };
|
|
6
7
|
}
|
|
8
|
+
async function settleAttempt(complete, fail, name, job, exit, afterFailure) {
|
|
9
|
+
if (Exit.isSuccess(exit)) {
|
|
10
|
+
if (exit.value !== deferredAttempt) {
|
|
11
|
+
await complete(name, job);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
await fail(name, job, failureOutput(exit.cause));
|
|
16
|
+
await afterFailure?.(job);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
export function batchHandler(client, name, run, afterFailure) {
|
|
8
20
|
const complete = client.complete?.bind(client);
|
|
9
21
|
const fail = client.fail?.bind(client);
|
|
@@ -26,13 +38,7 @@ export function batchHandler(client, name, run, afterFailure) {
|
|
|
26
38
|
// Returning would let pg-boss complete the unprocessed jobs; its expiry owns them instead.
|
|
27
39
|
return new Promise(() => undefined);
|
|
28
40
|
}
|
|
29
|
-
|
|
30
|
-
await complete(name, job);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
await fail(name, job, failureOutput(exit.cause));
|
|
34
|
-
await afterFailure?.(job);
|
|
35
|
-
}
|
|
41
|
+
await settleAttempt(complete, fail, name, job, exit, afterFailure);
|
|
36
42
|
}
|
|
37
43
|
if (expired) {
|
|
38
44
|
return new Promise(() => undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchHandler.js","sourceRoot":"","sources":["../../../src/server/internal/batchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"batchHandler.js","sourceRoot":"","sources":["../../../src/server/internal/batchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,SAAS,aAAa,CAAC,KAA2B;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACzF,CAAC;AAED,KAAK,UAAU,aAAa,CAC3B,QAA+C,EAC/C,IAAuC,EACvC,IAAY,EACZ,GAAiB,EACjB,IAAiC,EACjC,YAAmD;IAEnD,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;SAAM,CA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E,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YACzI,CAAC,CAAC,EACF,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CACtB,CAAC;YACF,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACrF,2FAA2F;gBAC3F,OAAO,IAAI,OAAO,CAAQ,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC5C,CAAC;YACD,MAAM,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,OAAO,CAAQ,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { Job } from "pg-boss";
|
|
3
|
+
import type { PgBossClient } from "#client.ts";
|
|
4
|
+
import { RetryAt } from "#definition.ts";
|
|
5
|
+
import { deferredAttempt } from "#internal/deferral.ts";
|
|
6
|
+
export declare function deferrableAttempt<A, E, R>(effect: Effect.Effect<A, E, R>, client: PgBossClient, schema: string, job: Job<unknown>, maxDeferrals: number): Effect.Effect<typeof deferredAttempt | A, Exclude<E, import("effect/Types").NoInfer<E> & RetryAt> | (import("effect/Types").NoInfer<E> & RetryAt), R>;
|
|
7
|
+
//# sourceMappingURL=deferrableAttempt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferrableAttempt.d.ts","sourceRoot":"","sources":["../../../src/server/internal/deferrableAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAU,MAAM,QAAQ,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAqB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAQ3E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACxC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,EACjB,YAAY,EAAE,MAAM,yJAuBpB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Clock, DateTime, Effect, Schema } from "effect";
|
|
2
|
+
import { RetryAt } from "#definition.ts";
|
|
3
|
+
import { deferralObservers, deferredAttempt } from "#internal/deferral.ts";
|
|
4
|
+
import { settleDeferral } from "#internal/settleDeferral.ts";
|
|
5
|
+
const recordDeferral = Effect.fnUntraced(function* (at, reason) {
|
|
6
|
+
const span = yield* Effect.currentSpan.pipe(Effect.orDie);
|
|
7
|
+
span.event("job.deferred", yield* Clock.currentTimeNanos, { at, reason });
|
|
8
|
+
});
|
|
9
|
+
export function deferrableAttempt(effect, client, schema, job, maxDeferrals) {
|
|
10
|
+
return effect.pipe(Effect.catchIf(Schema.is(RetryAt), (error) => {
|
|
11
|
+
if (maxDeferrals === 0) {
|
|
12
|
+
return Effect.fail(error);
|
|
13
|
+
}
|
|
14
|
+
const at = DateTime.formatIso(error.at);
|
|
15
|
+
return Effect.promise(() => settleDeferral(client, schema, job, at, error.reason, maxDeferrals)).pipe(Effect.flatMap((settled) => {
|
|
16
|
+
if (settled.claimed && !settled.deferred) {
|
|
17
|
+
return Effect.fail(error);
|
|
18
|
+
}
|
|
19
|
+
// Native batch settlement must not match a sibling's new claim at the unchanged retry count.
|
|
20
|
+
job.retryCount = Number.MAX_SAFE_INTEGER;
|
|
21
|
+
if (settled.deferred) {
|
|
22
|
+
deferralObservers.get(client)?.();
|
|
23
|
+
}
|
|
24
|
+
return (settled.deferred ? recordDeferral(at, error.reason) : Effect.void).pipe(Effect.as(deferredAttempt));
|
|
25
|
+
}));
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=deferrableAttempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferrableAttempt.js","sourceRoot":"","sources":["../../../src/server/internal/deferrableAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAU,EAAE,MAAc;IAC7E,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1D,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,iBAAiB,CAChC,MAA8B,EAC9B,MAAoB,EACpB,MAAc,EACd,GAAiB,EACjB,YAAoB;IAEpB,OAAO,MAAM,CAAC,IAAI,CACjB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;QAC5C,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxC,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CACpG,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC1C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YACD,6FAA6F;YAC7F,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;YACzC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACtB,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACnC,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;QAC7G,CAAC,CAAC,CACF,CAAC;IACH,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Job } from "pg-boss";
|
|
3
|
+
import type { PgBossClient } from "#client.ts";
|
|
4
|
+
export declare const deferredAttempt: unique symbol;
|
|
5
|
+
export declare const deferralObservers: WeakMap<PgBossClient, () => void>;
|
|
6
|
+
export declare const STATELY_DEFERRAL_POLICY = "effect-stately-deferred";
|
|
7
|
+
export declare const Deferral: Schema.Struct<{
|
|
8
|
+
readonly at: Schema.String;
|
|
9
|
+
readonly reason: Schema.String;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function deferralOf(job: Job<unknown>): {
|
|
12
|
+
readonly at: string;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
//# sourceMappingURL=deferral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferral.d.ts","sourceRoot":"","sources":["../../../src/server/internal/deferral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,eAAe,eAA4B,CAAC;AACzD,eAAO,MAAM,iBAAiB,8BAAmC,IAAI,CAAG,CAAC;AACzE,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE,eAAO,MAAM,QAAQ;;;EAGnB,CAAC;AAIH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC;;;cAG3C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export const deferredAttempt = Symbol("deferredAttempt");
|
|
3
|
+
export const deferralObservers = new WeakMap();
|
|
4
|
+
export const STATELY_DEFERRAL_POLICY = "effect-stately-deferred";
|
|
5
|
+
export const Deferral = Schema.Struct({
|
|
6
|
+
at: Schema.String,
|
|
7
|
+
reason: Schema.String,
|
|
8
|
+
});
|
|
9
|
+
const Output = Schema.Struct({ jobDeferral: Deferral });
|
|
10
|
+
export function deferralOf(job) {
|
|
11
|
+
const output = Reflect.get(job, "output");
|
|
12
|
+
return Schema.is(Output)(output) ? output.jobDeferral : undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=deferral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferral.js","sourceRoot":"","sources":["../../../src/server/internal/deferral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAA4B,CAAC;AACzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM;CACrB,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;AAExD,MAAM,UAAU,UAAU,CAAC,GAAiB;IAC3C,MAAM,MAAM,GAAY,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferralStorePlan.d.ts","sourceRoot":"","sources":["../../../src/server/internal/deferralStorePlan.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA+BxD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { STATELY_DEFERRAL_POLICY } from "./deferral.js";
|
|
2
|
+
export function deferralStorePlan(schema) {
|
|
3
|
+
const quoted = `"${schema.replaceAll('"', '""')}"`;
|
|
4
|
+
const jobTable = `${quoted}.job`.replaceAll("'", "''");
|
|
5
|
+
const key = `${schema}.effect_job_deferral`.replaceAll("'", "''");
|
|
6
|
+
const body = `BEGIN
|
|
7
|
+
PERFORM pg_advisory_xact_lock(hashtextextended('${key}', 0));
|
|
8
|
+
CREATE TABLE IF NOT EXISTS ${quoted}.effect_job_deferral (
|
|
9
|
+
name text NOT NULL,
|
|
10
|
+
id uuid NOT NULL,
|
|
11
|
+
created_on timestamptz NOT NULL,
|
|
12
|
+
count bigint NOT NULL,
|
|
13
|
+
keep_until timestamptz NOT NULL,
|
|
14
|
+
PRIMARY KEY (name, id)
|
|
15
|
+
);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS effect_job_deferral_keep_until ON ${quoted}.effect_job_deferral (keep_until);
|
|
17
|
+
CREATE OR REPLACE FUNCTION ${quoted}.effect_stately_deferral() RETURNS trigger LANGUAGE plpgsql AS $claim$
|
|
18
|
+
BEGIN
|
|
19
|
+
IF NEW.policy = '${STATELY_DEFERRAL_POLICY}' AND NEW.state = 'active' THEN
|
|
20
|
+
NEW.policy := 'stately';
|
|
21
|
+
END IF;
|
|
22
|
+
RETURN NEW;
|
|
23
|
+
END
|
|
24
|
+
$claim$;
|
|
25
|
+
IF NOT EXISTS (
|
|
26
|
+
SELECT 1 FROM pg_trigger WHERE tgrelid = '${jobTable}'::regclass AND tgname = 'effect_stately_deferral'
|
|
27
|
+
) THEN
|
|
28
|
+
CREATE TRIGGER effect_stately_deferral BEFORE UPDATE OF state, policy ON ${quoted}.job
|
|
29
|
+
FOR EACH ROW EXECUTE FUNCTION ${quoted}.effect_stately_deferral();
|
|
30
|
+
END IF;
|
|
31
|
+
END`;
|
|
32
|
+
return `DO '${body.replaceAll("'", "''")}'`;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=deferralStorePlan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deferralStorePlan.js","sourceRoot":"","sources":["../../../src/server/internal/deferralStorePlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC/C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;IACnD,MAAM,QAAQ,GAAG,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,GAAG,MAAM,sBAAsB,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG;oDACsC,GAAG;+BACxB,MAAM;;;;;;;;iEAQ4B,MAAM;+BACxC,MAAM;;sBAEf,uBAAuB;;;;;;;+CAOE,QAAQ;;8EAEuB,MAAM;mCACjD,MAAM;;KAEpC,CAAC;IACL,OAAO,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QueueOptions } from "#definition.ts";
|
|
2
|
+
export declare function maxDeferrals(options: QueueOptions | undefined): number;
|
|
3
|
+
export declare function nativeQueueOptions(options: QueueOptions | undefined): Readonly<{
|
|
4
|
+
expireInSeconds?: number;
|
|
5
|
+
retentionSeconds?: number;
|
|
6
|
+
deleteAfterSeconds?: number;
|
|
7
|
+
retryLimit?: number;
|
|
8
|
+
retryDelay?: number;
|
|
9
|
+
retryBackoff?: boolean;
|
|
10
|
+
retryDelayMax?: number;
|
|
11
|
+
partition?: boolean;
|
|
12
|
+
warningQueueSize?: number;
|
|
13
|
+
heartbeatSeconds?: number;
|
|
14
|
+
notify?: boolean;
|
|
15
|
+
policy?: import("#definition.ts").QueuePolicy;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=definitionOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitionOptions.d.ts","sourceRoot":"","sources":["../../../src/server/internal/definitionOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAMtE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS;;;;;;;;;;;;;GAGnE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function maxDeferrals(options) {
|
|
2
|
+
const limit = options?.maxDeferrals ?? 10;
|
|
3
|
+
if (!Number.isSafeInteger(limit) || limit < 0) {
|
|
4
|
+
throw new RangeError("maxDeferrals must be a nonnegative safe integer");
|
|
5
|
+
}
|
|
6
|
+
return limit;
|
|
7
|
+
}
|
|
8
|
+
export function nativeQueueOptions(options) {
|
|
9
|
+
const { maxDeferrals: _limit, ...native } = options ?? {};
|
|
10
|
+
return Object.freeze(native);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=definitionOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitionOptions.js","sourceRoot":"","sources":["../../../src/server/internal/definitionOptions.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,OAAiC;IAC7D,MAAM,KAAK,GAAG,OAAO,EAAE,YAAY,IAAI,EAAE,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,UAAU,CAAC,iDAAiD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAiC;IACnE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC1D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Job, PgBoss } from "pg-boss";
|
|
2
|
-
export declare function expireAttempt(client: PgBoss, schema: string, job: Job<unknown
|
|
2
|
+
export declare function expireAttempt(client: PgBoss, schema: string, job: Job<unknown>, cause?: "expiry" | "heartbeat"): Promise<void>;
|
|
3
3
|
//# sourceMappingURL=expireAttempt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expireAttempt.d.ts","sourceRoot":"","sources":["../../../src/server/internal/expireAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"expireAttempt.d.ts","sourceRoot":"","sources":["../../../src/server/internal/expireAttempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,GAAE,QAAQ,GAAG,WAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB9I"}
|