@shivaedev/effect-pg-boss 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +57 -12
  3. package/dist/{client.d.ts → server/client.d.ts} +7 -1
  4. package/dist/server/client.d.ts.map +1 -0
  5. package/dist/server/client.js.map +1 -0
  6. package/dist/{definition.d.ts → server/definition.d.ts} +6 -6
  7. package/dist/server/definition.d.ts.map +1 -0
  8. package/dist/server/definition.js.map +1 -0
  9. package/dist/{error.d.ts → server/error.d.ts} +10 -1
  10. package/dist/server/error.d.ts.map +1 -0
  11. package/dist/{error.js → server/error.js} +5 -0
  12. package/dist/server/error.js.map +1 -0
  13. package/dist/{health.d.ts → server/health.d.ts} +6 -0
  14. package/dist/server/health.d.ts.map +1 -0
  15. package/dist/server/health.js.map +1 -0
  16. package/dist/server/internal/countsFor.d.ts +5 -0
  17. package/dist/server/internal/countsFor.d.ts.map +1 -0
  18. package/dist/server/internal/countsFor.js +27 -0
  19. package/dist/server/internal/countsFor.js.map +1 -0
  20. package/dist/server/internal/ensureQueue.d.ts +4 -0
  21. package/dist/server/internal/ensureQueue.d.ts.map +1 -0
  22. package/dist/server/internal/ensureQueue.js +27 -0
  23. package/dist/server/internal/ensureQueue.js.map +1 -0
  24. package/dist/server/internal/health.d.ts.map +1 -0
  25. package/dist/server/internal/health.js.map +1 -0
  26. package/dist/server/internal/jobControl.d.ts +5 -0
  27. package/dist/server/internal/jobControl.d.ts.map +1 -0
  28. package/dist/server/internal/jobControl.js +34 -0
  29. package/dist/server/internal/jobControl.js.map +1 -0
  30. package/dist/server/internal/lifecycle.d.ts.map +1 -0
  31. package/dist/server/internal/lifecycle.js.map +1 -0
  32. package/dist/{internal → server/internal}/register.d.ts +2 -1
  33. package/dist/server/internal/register.d.ts.map +1 -0
  34. package/dist/{internal → server/internal}/register.js +21 -28
  35. package/dist/server/internal/register.js.map +1 -0
  36. package/dist/{internal → server/internal}/service.d.ts +1 -1
  37. package/dist/server/internal/service.d.ts.map +1 -0
  38. package/dist/{internal → server/internal}/service.js +7 -2
  39. package/dist/server/internal/service.js.map +1 -0
  40. package/dist/{service.d.ts → server/service.d.ts} +8 -5
  41. package/dist/server/service.d.ts.map +1 -0
  42. package/dist/{service.js → server/service.js} +1 -1
  43. package/dist/server/service.js.map +1 -0
  44. package/docs/north-star.md +1 -1
  45. package/docs/roadmap.md +9 -3
  46. package/package.json +14 -14
  47. package/src/{client.ts → server/client.ts} +17 -1
  48. package/src/{definition.ts → server/definition.ts} +6 -6
  49. package/src/{error.ts → server/error.ts} +10 -1
  50. package/src/{health.ts → server/health.ts} +7 -0
  51. package/src/server/internal/countsFor.ts +33 -0
  52. package/src/server/internal/ensureQueue.ts +29 -0
  53. package/src/server/internal/jobControl.ts +46 -0
  54. package/src/{internal → server/internal}/register.ts +29 -31
  55. package/src/{internal → server/internal}/service.ts +7 -2
  56. package/src/{service.ts → server/service.ts} +13 -7
  57. package/dist/client.d.ts.map +0 -1
  58. package/dist/client.js.map +0 -1
  59. package/dist/definition.d.ts.map +0 -1
  60. package/dist/definition.js.map +0 -1
  61. package/dist/error.d.ts.map +0 -1
  62. package/dist/error.js.map +0 -1
  63. package/dist/health.d.ts.map +0 -1
  64. package/dist/health.js.map +0 -1
  65. package/dist/internal/health.d.ts.map +0 -1
  66. package/dist/internal/health.js.map +0 -1
  67. package/dist/internal/lifecycle.d.ts.map +0 -1
  68. package/dist/internal/lifecycle.js.map +0 -1
  69. package/dist/internal/register.d.ts.map +0 -1
  70. package/dist/internal/register.js.map +0 -1
  71. package/dist/internal/service.d.ts.map +0 -1
  72. package/dist/internal/service.js.map +0 -1
  73. package/dist/service.d.ts.map +0 -1
  74. package/dist/service.js.map +0 -1
  75. /package/dist/{client.js → server/client.js} +0 -0
  76. /package/dist/{definition.js → server/definition.js} +0 -0
  77. /package/dist/{health.js → server/health.js} +0 -0
  78. /package/dist/{internal → server/internal}/health.d.ts +0 -0
  79. /package/dist/{internal → server/internal}/health.js +0 -0
  80. /package/dist/{internal → server/internal}/lifecycle.d.ts +0 -0
  81. /package/dist/{internal → server/internal}/lifecycle.js +0 -0
  82. /package/src/{internal → server/internal}/health.ts +0 -0
  83. /package/src/{internal → server/internal}/lifecycle.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 - 2026-10-17
4
+
5
+ ### Added
6
+
7
+ - `PgBossService.counts(queue)` returns live `QueueCounts` without waiting for the pg-boss monitor; `health` keeps using cached counts.
8
+ - `PgBossService.getJob(queue, id)` returns optional job metadata with Schema-decoded payloads and decoding service requirements. `PgBossService.retry(queue, id)` reprocesses failed or retry-waiting jobs under their original ID.
9
+ - `PgBossQueueOptionsError` identifies immutable queue option conflicts during Layer acquisition. Custom `PgBossClient` factories can provide optional native `findJobs`, `retry`, `update`, `getDb` and `updateQueue` capabilities for the new operations.
10
+
11
+ ### Fixed
12
+
13
+ - Queue and schedule definitions accept pg-boss's full `Queue` options except the owned name and dead-letter setup, including notification delivery, policy, partitioning, heartbeat and backlog warnings.
14
+ - Startup reconciles declared mutable queue settings through `updateQueue`, including expiry and retry limits, so they reach existing queues after restart.
15
+
16
+ ## 0.5.0 - 2026-10-13
17
+
18
+ ### Added
19
+
20
+ - `Jobs.layer({ jobs: [Queue] })` registers a queue definition for producers without starting a worker. Its queue appears in health results and uses the same retry and dead-letter settings as a worker registration.
21
+
22
+ ### Breaking
23
+
24
+ - Requires stable Effect 4.0.4 in place of 4.0.0-rc.112. Effect 4.0.4 moves the former `effect/unstable/*` modules to `effect/*` and renames constructors such as `Config.string` to `Config.String`.
25
+
3
26
  ## 0.4.0 - 2026-10-12
4
27
 
5
28
  ### Changed
package/README.md CHANGED
@@ -31,7 +31,7 @@ A **queue definition** names a pg-boss queue and the Schema of its payload. Appl
31
31
 
32
32
  A **schedule definition** describes a queue with a cron trigger. `schedule.run(effect)` pairs it with an Effect that needs no payload. Queue workers and scheduled workers are **registrations**: the values you put in the jobs Layer's `jobs` list.
33
33
 
34
- The application creates one jobs service with `makePgBoss(identifier)`. Its Layer starts a client, registers the job list and captures the services those workers need. The Layer's scope owns its client reference and releases it when the scope ends; the final reference closes the client. Callers use the jobs service to enqueue a decoded payload or read queue health.
34
+ The application creates one jobs service with `makePgBoss(identifier)`. Its Layer starts a client, registers the job list and captures the services those workers need. The Layer's scope owns its client reference and releases it when the scope ends; the final reference closes the client. Callers use the jobs service to enqueue a decoded payload, look up or retry a job, or read queue health and live counts.
35
35
 
36
36
  Use a distinct literal identifier for each jobs service. The service and its Layer keep that identifier in their types, so providing a Layer for a different identifier leaves the required jobs service unprovided at compile time.
37
37
 
@@ -116,7 +116,7 @@ export const jobsLayer = (databaseUrl: string) =>
116
116
  }).pipe(Layer.provide(MailLive));
117
117
  ```
118
118
 
119
- The constructor options belong to pg-boss. `jobs` is the complete list of registrations for this Layer. The Layer captures `MailLive` for both the queue handler and the scheduled Effect. A startup or registration failure fails Layer acquisition with `PgBossError` and releases its acquired client reference. A shared client stays running while another scope still owns a reference.
119
+ The constructor options belong to pg-boss. `jobs` is the complete list of registrations for this Layer. The Layer captures `MailLive` for both the queue handler and the scheduled Effect. A startup or registration failure fails Layer acquisition with `PgBossError` or `PgBossQueueOptionsError` and releases its acquired client reference. A shared client stays running while another scope still owns a reference.
120
120
 
121
121
  Keep the Layer in the application's worker runtime scope. A short scope is useful for an acquisition or health check; a worker process needs its scope to remain open while it handles jobs.
122
122
 
@@ -173,7 +173,35 @@ export const readJobCounts = Effect.gen(function* () {
173
173
  });
174
174
  ```
175
175
 
176
- `health` exposes pg-boss queue counts as data. Its total fields include the registered queue's active, failed, queued and ready counts, plus the dead-letter queue's queued count. Decide in the application which values affect an HTTP health response or an alert.
176
+ `health` exposes pg-boss cached queue counts as data. It stays cheap and follows the pg-boss monitor interval; it does not establish that a queue has just drained. Its total fields include the registered queue's active, failed, queued and ready counts, plus the dead-letter queue's queued count. Decide in the application which values affect an HTTP health response or an alert.
177
+
178
+ ### Read live counts and retry a job
179
+
180
+ ```ts
181
+ import { Effect, Option } from "effect";
182
+ import { SendEmail } from "./jobs.ts";
183
+ import { Jobs } from "./services.ts";
184
+
185
+ export const inspectEmail = (id: string) => Effect.gen(function* () {
186
+ const jobs = yield* Jobs;
187
+ const job = yield* jobs.getJob(SendEmail, id);
188
+ if (Option.isSome(job) && job.value.state === "failed") {
189
+ yield* jobs.retry(SendEmail, id);
190
+ }
191
+ const counts = yield* jobs.counts(SendEmail);
192
+ return counts.queuedCount === 0 && counts.activeCount === 0;
193
+ });
194
+ ```
195
+
196
+ `counts(queue)` reads the job table directly on each call. `queuedCount` includes created and retry-waiting jobs, including future jobs; `activeCount` counts running jobs, `failedCount` counts retained failures, and `totalCount` includes retained terminal jobs. A queue has drained when queued and active counts are both zero. These counts are a snapshot, so a producer can enqueue more work after the query returns.
197
+
198
+ `getJob(queue, id)` returns `None` when the ID is absent, or `Some` pg-boss job metadata with `data` decoded by the queue's Schema. Invalid stored data fails with `PgBossPayloadError`, and the Effect requires the Schema's decoding services. `retry(queue, id)` reuses the original ID: it makes a failed job eligible for another attempt and pulls a retry-waiting job forward to run now. Missing IDs and jobs in other states are left unchanged. It does not remove an earlier copy from the dead-letter queue.
199
+
200
+ ### Queue settings on startup
201
+
202
+ `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. The PostgreSQL notification test waits for an idle worker with a ten-second polling interval and verifies delivery within 1.5 seconds.
203
+
204
+ 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.
177
205
 
178
206
  ### Share a client between Layer builds
179
207
 
@@ -193,6 +221,20 @@ const sharedJobsLayer = (databaseUrl: string) =>
193
221
 
194
222
  Overlapping Layer builds with the same `clientCacheKey` share one started client. The later build replaces the registered worker, and the final scope release stops the shared client. A later build after that release starts a new client. Without a key, each build creates its own client. The application chooses whether to pass a key.
195
223
 
224
+ ### Separate producers and workers
225
+
226
+ Pass a queue definition directly in the jobs Layer to create its queue and dead-letter queue without starting a consumer:
227
+
228
+ ```ts
229
+ import { SendEmail } from "./jobs.ts";
230
+ import { Jobs } from "./services.ts";
231
+
232
+ export const producerLayer = (databaseUrl: string) =>
233
+ Jobs.layer({ connectionString: databaseUrl, jobs: [SendEmail] });
234
+ ```
235
+
236
+ Provide this Layer to the request runtime and call `jobs.enqueue(SendEmail, { userId })` as above. A separate worker process registers `SendEmail.handle(...)` against the same database. Producer queues use the same retry options and appear in `health`; only worker registrations capture handler services. The PostgreSQL producer test creates both queues through this Layer, enqueues a transformed payload, and observes a failing worker exhaust two retries before the job reaches its dead-letter queue.
237
+
196
238
  ### API
197
239
 
198
240
  Import the module that defines the name; the package has no root entry.
@@ -201,20 +243,23 @@ Import the module that defines the name; the package has no root entry.
201
243
  | --- | --- |
202
244
  | `@shivaedev/effect-pg-boss/definition.ts` | `defineQueue`, `defineSchedule`, `jobContext`; `DefineQueueOptions`, `DefineScheduleOptions`, `JobContext`, `JobPayloadSchema`, `JobRegistration`, `QueueDefinition`, `QueueWorker`, `RegistrationRequirements`, `ScheduleDefinition`, `ScheduledWorker` |
203
245
  | `@shivaedev/effect-pg-boss/service.ts` | `makePgBoss`; `PgBossDefinition`, `PgBossLayerOptions`, `PgBossService` |
204
- | `@shivaedev/effect-pg-boss/health.ts` | `deadLetterQueueName`; `JobsHealth`, `QueueHealth` |
205
- | `@shivaedev/effect-pg-boss/error.ts` | `PgBossError`, `PgBossPayloadError`, `toPgBossError`; `PgBossOperation` |
246
+ | `@shivaedev/effect-pg-boss/health.ts` | `deadLetterQueueName`; `JobsHealth`, `QueueCounts`, `QueueHealth` |
247
+ | `@shivaedev/effect-pg-boss/error.ts` | `PgBossError`, `PgBossPayloadError`, `PgBossQueueOptionsError`, `toPgBossError`; `PgBossOperation` |
206
248
  | `@shivaedev/effect-pg-boss/client.ts` | `defaultClientFactory`; `PgBossClient`, `PgBossClientFactory` |
207
249
 
208
- The definition options keep the pg-boss names: `queue` uses `QueueOptions` except `deadLetter`, `worker` uses `WorkOptions`, and a schedule's `schedule` uses `ScheduleOptions`. A queue also requires `name` and `schema`; a schedule requires `name` and `cron`.
250
+ 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`.
209
251
 
210
- The application's service has two operations:
252
+ The application's service has these operations:
211
253
 
212
254
  - `enqueue(queue, payload, options?)`: an Effect returning `Option.Option<string>`, with `PgBossError | PgBossPayloadError` in its error type. Its options use pg-boss `SendOptions`.
213
- - `health`: an Effect returning `JobsHealth`, with `PgBossError` in its error type.
255
+ - `health`: an Effect returning cached `JobsHealth`, with `PgBossError` in its error type.
256
+ - `counts(queue)`: an Effect returning live `QueueCounts`, with `PgBossError` in its error type.
257
+ - `getJob(queue, id)`: an Effect returning `Option.Option<JobWithMetadata<Payload>>` with decoded payload data, `PgBossError | PgBossPayloadError` in its error type and the Schema's decoding services in its requirements.
258
+ - `retry(queue, id)`: an Effect returning `void`, with `PgBossError` in its error type.
214
259
 
215
- `Jobs.layer(options)` accepts pg-boss `ConstructorOptions` plus `jobs`, optional `clientCacheKey`, optional `clientFactory`, optional `onError` and optional `stop`. The factory type accepts constructor options and returns `PgBossClient`; `onError` has the type `(error: Error) => Effect.Effect<unknown, never, R>`; `stop` uses pg-boss `StopOptions`.
260
+ `Jobs.layer(options)` accepts pg-boss `ConstructorOptions` plus `jobs`, optional `clientCacheKey`, optional `clientFactory`, optional `onError` and optional `stop`. The factory type accepts constructor options and returns `PgBossClient`. Custom clients can 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. `onError` has the type `(error: Error) => Effect.Effect<unknown, never, R>`; `stop` uses pg-boss `StopOptions`.
216
261
 
217
- `onError` handles pg-boss client `error` events using the services captured by the Layer. The Layer's requirement type includes the workers' services, the payload Schemas' `DecodingServices` and the callback's services. `enqueue` includes the payload Schema's `EncodingServices` in its requirement type.
262
+ `onError` handles pg-boss client `error` events using the services captured by the Layer. The Layer's requirement type includes the workers' services, the workers' payload Schemas' `DecodingServices` and the callback's services. `enqueue` includes the payload Schema's `EncodingServices` in its requirement type.
218
263
 
219
264
  `JobContext` has `id`, `name`, `signal`, `expireInSeconds` and `heartbeatSeconds`. `QueueHealth` has `name`, `activeCount`, `deadLetteredCount`, `failedCount`, `queuedCount` and `readyCount`. `JobsHealth` has `jobs` and the corresponding `activeTotal`, `deadLetteredTotal`, `failedTotal`, `queuedTotal` and `readyTotal` fields.
220
265
 
@@ -223,12 +268,12 @@ The application's service has two operations:
223
268
  ### Install, setup and limits
224
269
 
225
270
  ```sh
226
- pnpm add @shivaedev/effect-pg-boss effect@4.0.0-rc.112 pg-boss@12.23.1
271
+ pnpm add @shivaedev/effect-pg-boss effect@4.0.4 pg-boss@12.37.0
227
272
  ```
228
273
 
229
274
  The package requires Node.js 24 or later and PostgreSQL. `effect` and `pg-boss` are peers; use versions that satisfy the package's published peer ranges.
230
275
 
231
- Provide the database connection and job registrations at the application runtime boundary. Application services own the domain work and provider calls; pg-boss owns queue execution. Treat enqueueing and an application database transaction as separate operations, and choose any required transaction or outbox policy in the application.
276
+ Provide the database connection and job registrations at the application runtime boundary. Application services own the domain work and provider calls; pg-boss owns queue execution. Treat enqueueing and an application database transaction as separate operations. Enqueue after the application write commits, and handle queue failures in the application so they cannot roll back the write. The starter logs enqueue failures and returns the saved note; a failed enqueue leaves its word count pending. The package supplies no application transaction adapter.
232
277
 
233
278
  For package development, the real PostgreSQL test uses `PLATFORM_EFFECT_PG_BOSS_TEST_DATABASE_URL` and skips when the variable is absent. A skipped test does not establish durable queue behavior. Fake-client tests cover registration and lifecycle calls; they do not establish real cron execution, retry timing or deployment behavior. The package is built for ShivaeDev applications and may change without a deprecation period.
234
279
 
@@ -1,14 +1,20 @@
1
- import type { ConstructorOptions, Job, Queue, QueueResult, ScheduleOptions, SendOptions, StopOptions, WorkOptions } from "pg-boss";
1
+ import type { ConstructorOptions, FindJobsOptions, Job, JobWithMetadata, Queue, QueueResult, ScheduleOptions, SendOptions, StopOptions, WorkOptions } from "pg-boss";
2
+ import { PgBoss } from "pg-boss";
2
3
  export interface PgBossClient {
3
4
  readonly createQueue: (name: string, options?: Omit<Queue, "name">) => Promise<void>;
5
+ readonly findJobs?: (name: string, options?: FindJobsOptions) => Promise<readonly JobWithMetadata<unknown>[]>;
6
+ readonly getDb?: PgBoss["getDb"];
4
7
  readonly getQueue: (name: string) => Promise<QueueResult | null>;
5
8
  readonly off: (event: "error", listener: (error: Error) => void) => unknown;
6
9
  readonly offWork: (name: string) => Promise<void>;
7
10
  readonly on: (event: "error", listener: (error: Error) => void) => unknown;
11
+ readonly retry?: PgBoss["retry"];
8
12
  readonly schedule: (name: string, cron: string, data?: object | null, options?: ScheduleOptions) => Promise<void>;
9
13
  readonly send: (name: string, data?: object | null, options?: SendOptions) => Promise<string | null>;
10
14
  readonly start: () => Promise<unknown>;
11
15
  readonly stop: (options?: StopOptions) => Promise<void>;
16
+ readonly update?: PgBoss["update"];
17
+ readonly updateQueue?: PgBoss["updateQueue"];
12
18
  readonly work: (name: string, options: WorkOptions, handler: (jobs: readonly Job<unknown>[]) => Promise<unknown>) => Promise<string>;
13
19
  }
14
20
  export type PgBossClientFactory = (options: ConstructorOptions) => PgBossClient;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/server/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAC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EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClH,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACrG,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACrI;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,YAAY,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,mBAAsD,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/server/client.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAsBjC,MAAM,CAAC,MAAM,oBAAoB,GAAwB,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Effect, Schema } from "effect";
2
- import type { Job, QueueOptions, ScheduleOptions, WorkOptions } from "pg-boss";
2
+ import type { Job, Queue, ScheduleOptions, WorkOptions } from "pg-boss";
3
3
  export interface JobPayloadSchema extends Schema.Top {
4
4
  readonly Encoded: object;
5
5
  readonly Type: object;
@@ -15,7 +15,7 @@ export interface QueueDefinition<Name extends string = string, Payload extends J
15
15
  readonly _tag: "QueueDefinition";
16
16
  readonly handle: <E, R>(handler: (payload: Schema.Schema.Type<Payload>, job: JobContext) => Effect.Effect<unknown, E, R>) => QueueWorker<Payload, R>;
17
17
  readonly name: Name;
18
- readonly queueOptions: Omit<QueueOptions, "deadLetter">;
18
+ readonly queueOptions: Omit<Queue, "name" | "deadLetter">;
19
19
  readonly schema: Payload;
20
20
  readonly workerOptions: WorkOptions;
21
21
  }
@@ -25,13 +25,13 @@ export interface QueueWorker<Payload extends JobPayloadSchema = JobPayloadSchema
25
25
  readonly queue: QueueDefinition<string, Payload>;
26
26
  }
27
27
  export interface JobRegistration {
28
- readonly _tag: "QueueWorker" | "ScheduledWorker";
28
+ readonly _tag: "QueueDefinition" | "QueueWorker" | "ScheduledWorker";
29
29
  }
30
30
  export interface ScheduleDefinition<Name extends string = string> {
31
31
  readonly _tag: "ScheduleDefinition";
32
32
  readonly cron: string;
33
33
  readonly name: Name;
34
- readonly queueOptions: Omit<QueueOptions, "deadLetter">;
34
+ readonly queueOptions: Omit<Queue, "name" | "deadLetter">;
35
35
  readonly run: <E, R>(effect: Effect.Effect<unknown, E, R>) => ScheduledWorker<R>;
36
36
  readonly scheduleOptions: ScheduleOptions;
37
37
  readonly workerOptions: WorkOptions;
@@ -44,7 +44,7 @@ export interface ScheduledWorker<Requirements = unknown> {
44
44
  export type RegistrationRequirements<Registrations extends readonly JobRegistration[]> = Registrations[number] extends infer Registration ? Registration extends QueueWorker<infer Payload, infer Requirements> ? Requirements | Payload["DecodingServices"] : Registration extends ScheduledWorker<infer Requirements> ? Requirements : never : never;
45
45
  export interface DefineQueueOptions<Name extends string, Payload extends JobPayloadSchema> {
46
46
  readonly name: Name;
47
- readonly queue?: Omit<QueueOptions, "deadLetter">;
47
+ readonly queue?: Omit<Queue, "name" | "deadLetter">;
48
48
  readonly schema: Payload;
49
49
  readonly worker?: WorkOptions;
50
50
  }
@@ -52,7 +52,7 @@ export declare const defineQueue: <const Name extends string, const Payload exte
52
52
  export interface DefineScheduleOptions<Name extends string> {
53
53
  readonly cron: string;
54
54
  readonly name: Name;
55
- readonly queue?: Omit<QueueOptions, "deadLetter">;
55
+ readonly queue?: Omit<Queue, "name" | "deadLetter">;
56
56
  readonly schedule?: ScheduleOptions;
57
57
  readonly worker?: WorkOptions;
58
58
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../src/server/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,GAAG;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,gBAAgB,GAAG,gBAAgB;IACjH,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EACrB,OAAO,EAAE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,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAC;AAUF,MAAM,CAAC,MAAM,cAAc,GAAG,CAA4B,OAAoC,EAA4B,EAAE;IAC3H,MAAM,UAAU,GAA6B;QAC5C,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACjD,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CACf,MAAM,CAAC,MAAM,CAAC;YACb,IAAI,EAAE,iBAA0B;YAChC,MAAM;YACN,QAAQ,EAAE,UAAU;SACpB,CAAC;QACH,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAClE,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;KACjE,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAiB,EAAc,EAAE,CAAC,CAAC;IAC7D,eAAe,EAAE,GAAG,CAAC,eAAe;IACpC,gBAAgB,EAAE,GAAG,CAAC,gBAAgB;IACtC,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Redacted } from "effect";
2
- export type PgBossOperation = "enqueue" | "health" | "register" | "start" | "stop";
2
+ export type PgBossOperation = "counts" | "enqueue" | "getJob" | "health" | "register" | "retry" | "start" | "stop";
3
3
  declare const PgBossError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
4
4
  readonly _tag: "PgBossError";
5
5
  } & Readonly<A>;
@@ -9,6 +9,15 @@ export declare class PgBossError extends PgBossError_base<{
9
9
  readonly original: Redacted.Redacted<unknown>;
10
10
  }> {
11
11
  }
12
+ declare const PgBossQueueOptionsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
13
+ readonly _tag: "PgBossQueueOptionsError";
14
+ } & Readonly<A>;
15
+ export declare class PgBossQueueOptionsError extends PgBossQueueOptionsError_base<{
16
+ readonly queue: string;
17
+ readonly options: readonly ("partition" | "policy")[];
18
+ }> {
19
+ get message(): string;
20
+ }
12
21
  declare const PgBossPayloadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
13
22
  readonly _tag: "PgBossPayloadError";
14
23
  } & Readonly<A>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/server/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;;;;AAEnH,qBAAa,WAAY,SAAQ,iBAAgC;IAChE,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;CAAG;;;;AAEL,qBAAa,uBAAwB,SAAQ,6BAA4C;IACxF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,QAAQ,CAAC,EAAE,CAAC;CACtD,CAAC;IACD,IAAa,OAAO,IAAI,MAAM,CAE7B;CACD;;;;AAED,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC9E,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;CAAG;AAEL,eAAO,MAAM,aAAa,cAAe,eAAe,SAAS,OAAO,UAAU,MAAM,KAAG,WAKxF,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import { Data, Redacted } from "effect";
2
2
  export class PgBossError extends Data.TaggedError("PgBossError") {
3
3
  }
4
+ export class PgBossQueueOptionsError extends Data.TaggedError("PgBossQueueOptionsError") {
5
+ get message() {
6
+ return `Queue ${this.queue} cannot change options after creation: ${this.options.join(", ")}`;
7
+ }
8
+ }
4
9
  export class PgBossPayloadError extends Data.TaggedError("PgBossPayloadError") {
5
10
  }
6
11
  export const toPgBossError = (operation, error, queue) => new PgBossError({
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/server/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIxC,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAI7D;CAAG;AAEL,MAAM,OAAO,uBAAwB,SAAQ,IAAI,CAAC,WAAW,CAAC,yBAAyB,CAGrF;IACD,IAAa,OAAO;QACnB,OAAO,SAAS,IAAI,CAAC,KAAK,0CAA0C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC/F,CAAC;CACD;AAED,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAI3E;CAAG;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAA0B,EAAE,KAAc,EAAE,KAAc,EAAe,EAAE,CACxG,IAAI,WAAW,CAAC;IACf,SAAS;IACT,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;IAC9B,KAAK;CACL,CAAC,CAAC"}
@@ -1,3 +1,9 @@
1
+ export interface QueueCounts {
2
+ readonly activeCount: number;
3
+ readonly failedCount: number;
4
+ readonly queuedCount: number;
5
+ readonly totalCount: number;
6
+ }
1
7
  export interface QueueHealth {
2
8
  readonly activeCount: number;
3
9
  readonly deadLetteredCount: number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,mBAAmB,cAAe,MAAM,KAAG,MAA4B,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,GAAG,SAAS,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import type { PgBossClient } from "#client.ts";
3
+ import type { QueueCounts } from "#health.ts";
4
+ export declare function countsFor(client: PgBossClient, schema: string, name: string): Effect.Effect<QueueCounts, import("#error.ts").PgBossError>;
5
+ //# sourceMappingURL=countsFor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countsFor.d.ts","sourceRoot":"","sources":["../../../src/server/internal/countsFor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,WAAW,EAAE,WAAW,CAAC,CAoBzI"}
@@ -0,0 +1,27 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { toPgBossError } from "#error.ts";
3
+ const Counts = Schema.Struct({
4
+ activeCount: Schema.Number,
5
+ failedCount: Schema.Number,
6
+ queuedCount: Schema.Number,
7
+ totalCount: Schema.Number,
8
+ });
9
+ export function countsFor(client, schema, name) {
10
+ return Effect.tryPromise({
11
+ catch: (error) => toPgBossError("counts", error, name),
12
+ try: async () => {
13
+ if (client.getDb === undefined) {
14
+ throw new TypeError("This pg-boss client does not support getDb");
15
+ }
16
+ const quotedSchema = `"${schema.replaceAll('"', '""')}"`;
17
+ const { rows } = await client.getDb().executeSql(`SELECT
18
+ count(*) FILTER (WHERE state = 'active')::int AS "activeCount",
19
+ count(*) FILTER (WHERE state = 'failed')::int AS "failedCount",
20
+ count(*) FILTER (WHERE state IN ('created', 'retry'))::int AS "queuedCount",
21
+ count(*)::int AS "totalCount"
22
+ FROM ${quotedSchema}.job WHERE name = $1`, [name]);
23
+ return Schema.decodeUnknownPromise(Counts)(rows[0]);
24
+ },
25
+ });
26
+ }
27
+ //# sourceMappingURL=countsFor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countsFor.js","sourceRoot":"","sources":["../../../src/server/internal/countsFor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM;IAC1B,WAAW,EAAE,MAAM,CAAC,MAAM;IAC1B,WAAW,EAAE,MAAM,CAAC,MAAM;IAC1B,UAAU,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,CAAC;AAEH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,MAAc,EAAE,IAAY;IAC3E,OAAO,MAAM,CAAC,UAAU,CAAC;QACxB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC;QACtD,GAAG,EAAE,KAAK,IAAI,EAAE;YACf,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACnE,CAAC;YACD,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;YACzD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,UAAU,CAC/C;;;;;WAKO,YAAY,sBAAsB,EACzC,CAAC,IAAI,CAAC,CACN,CAAC;YACF,OAAO,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Queue } from "pg-boss";
2
+ import type { PgBossClient } from "#client.ts";
3
+ export declare function ensureQueue(client: PgBossClient, name: string, options: Omit<Queue, "name" | "deadLetter">): Promise<void>;
4
+ //# sourceMappingURL=ensureQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureQueue.d.ts","sourceRoot":"","sources":["../../../src/server/internal/ensureQueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,wBAAsB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhI"}
@@ -0,0 +1,27 @@
1
+ import { PgBossQueueOptionsError } from "#error.ts";
2
+ import { deadLetterQueueName } from "#health.ts";
3
+ export async function ensureQueue(client, name, options) {
4
+ const deadLetter = deadLetterQueueName(name);
5
+ const desired = { retryBackoff: true, retryLimit: 3, ...options, deadLetter };
6
+ await client.createQueue(deadLetter);
7
+ await client.createQueue(name, desired);
8
+ const existing = await client.getQueue(name);
9
+ if (existing === null) {
10
+ return;
11
+ }
12
+ const immutable = ["partition", "policy"].filter((key) => desired[key] !== undefined && desired[key] !== existing[key]);
13
+ if (immutable.length > 0) {
14
+ throw new PgBossQueueOptionsError({ options: immutable, queue: name });
15
+ }
16
+ const { partition: _partition, policy: _policy, ...mutable } = desired;
17
+ const changed = Object.entries(mutable).some(([key, value]) => value !== undefined && value !== Reflect.get(existing, key));
18
+ if (!changed) {
19
+ return;
20
+ }
21
+ if (client.updateQueue === undefined) {
22
+ throw new TypeError("This pg-boss client does not support updateQueue");
23
+ }
24
+ // pg-boss validates retryDelayMax against retryBackoff in the same update.
25
+ await client.updateQueue(name, mutable);
26
+ }
27
+ //# sourceMappingURL=ensureQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureQueue.js","sourceRoot":"","sources":["../../../src/server/internal/ensureQueue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAoB,EAAE,IAAY,EAAE,OAA2C;IAChH,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC;IAC9E,MAAM,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO;IACR,CAAC;IACD,MAAM,SAAS,GAAI,CAAC,WAAW,E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AC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrB,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,iBAAiB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC5E,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,IAAI;IACJ,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;CAC9D,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { PgBossClient } from "#client.ts";
2
+ import type { PgBossService } from "#service.ts";
3
+ export declare function getJobFor(client: PgBossClient): PgBossService["getJob"];
4
+ export declare function retryFor(client: PgBossClient): PgBossService["retry"];
5
+ //# sourceMappingURL=jobControl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobControl.d.ts","sourceRoot":"","sources":["../../../src/server/internal/jobControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CAAC,QAAQ,CAAC,CAoBvE;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,aAAa,CAAC,OAAO,CAAC,CAkBrE"}
@@ -0,0 +1,34 @@
1
+ import { Effect, Option, Redacted, Schema } from "effect";
2
+ import { PgBossPayloadError, toPgBossError } from "#error.ts";
3
+ export function getJobFor(client) {
4
+ return (queue, id) => Effect.tryPromise({
5
+ catch: (error) => toPgBossError("getJob", error, queue.name),
6
+ try: async () => {
7
+ if (client.findJobs === undefined) {
8
+ throw new TypeError("This pg-boss client does not support findJobs");
9
+ }
10
+ return (await client.findJobs(queue.name, { id }))[0];
11
+ },
12
+ }).pipe(Effect.flatMap((job) => job === undefined
13
+ ? Effect.succeed(Option.none())
14
+ : Schema.decodeUnknownEffect(queue.schema)(job.data).pipe(Effect.mapError((error) => new PgBossPayloadError({ direction: "decode", original: Redacted.make(error), queue: queue.name })), Effect.map((data) => Option.some({ ...job, data })))));
15
+ }
16
+ export function retryFor(client) {
17
+ return (queue, id) => Effect.tryPromise({
18
+ catch: (error) => toPgBossError("retry", error, queue.name),
19
+ try: async () => {
20
+ if (client.findJobs === undefined || client.retry === undefined || client.update === undefined) {
21
+ throw new TypeError("This pg-boss client does not support findJobs, retry and update");
22
+ }
23
+ const job = (await client.findJobs(queue.name, { id }))[0];
24
+ if (job?.state !== "failed" && job?.state !== "retry") {
25
+ return;
26
+ }
27
+ if (job.state === "failed") {
28
+ await client.retry(queue.name, id);
29
+ }
30
+ await client.update(queue.name, undefined, { id, startAfter: 0 });
31
+ },
32
+ });
33
+ }
34
+ //# sourceMappingURL=jobControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobControl.js","sourceRoot":"","sources":["../../../src/server/internal/jobControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG9D,MAA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AAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACxC,OAAO;QACR,CAAC;QAED,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO;QACR,CAAC;QACD,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;CACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { type Context, Effect } from "effect";
2
2
  import type { PgBossClient } from "#client.ts";
3
3
  import { type JobRegistration } from "#definition.ts";
4
+ import { PgBossQueueOptionsError } from "#error.ts";
4
5
  export declare const registrationName: (registration: JobRegistration) => string;
5
6
  export declare const registrationNames: (registrations: readonly JobRegistration[]) => readonly string[];
6
- export declare const registerJobs: <R>(client: PgBossClient, registrations: readonly JobRegistration[], context: Context.Context<R>, replaceWorkers: boolean) => Effect.Effect<void, import("#error.ts").PgBossError>;
7
+ export declare const registerJobs: <R>(client: PgBossClient, registrations: readonly JobRegistration[], context: Context.Context<R>, replaceWorkers: boolean) => Effect.Effect<void, import("#error.ts").PgBossError | PgBossQueueOptionsError>;
7
8
  //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/server/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAA4E,MAAM,gBAAgB,CAAC;AAChI,OAAO,EAAsB,uBAAuB,EAAiB,MAAM,WAAW,CAAC;AAevF,eAAO,MAAM,gBAAgB,iBAAkB,eAAe,KAAG,MAWhE,CAAC;AAqEF,eAAO,MAAM,iBAAiB,kBAAmB,SAAS,eAAe,EAAE,KAAG,SAAS,MAAM,EAM5F,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,UACrB,YAAY,iBACL,SAAS,eAAe,EAAE,WAChC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,kBACX,OAAO,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,WAAW,GAAG,uBAAuB,CAc7E,CAAC"}
@@ -1,21 +1,20 @@
1
1
  import { Effect, Redacted, Schema } from "effect";
2
2
  import { jobContext } from "#definition.ts";
3
- import { PgBossPayloadError, toPgBossError } from "#error.ts";
4
- import { deadLetterQueueName } from "#health.ts";
5
- function queueOptions(options) {
6
- return {
7
- retryBackoff: true,
8
- retryLimit: 3,
9
- ...options,
10
- };
11
- }
3
+ import { PgBossPayloadError, PgBossQueueOptionsError, toPgBossError } from "#error.ts";
4
+ import { ensureQueue } from "#internal/ensureQueue.ts";
12
5
  function isQueueWorker(registration) {
13
6
  return registration._tag === "QueueWorker";
14
7
  }
15
8
  function isScheduledWorker(registration) {
16
9
  return registration._tag === "ScheduledWorker";
17
10
  }
11
+ function isQueueDefinition(registration) {
12
+ return registration._tag === "QueueDefinition";
13
+ }
18
14
  export const registrationName = (registration) => {
15
+ if (isQueueDefinition(registration)) {
16
+ return registration.name;
17
+ }
19
18
  if (isQueueWorker(registration)) {
20
19
  return registration.queue.name;
21
20
  }
@@ -34,34 +33,28 @@ function runQueueWorker(worker, job, context) {
34
33
  queue: worker.queue.name,
35
34
  })), Effect.flatMap((payload) => worker.handler(payload, jobContext(job))), Effect.provide(context)), { signal: job.signal });
36
35
  }
37
- async function registerQueue(client, worker, context, replaceWorker) {
38
- const name = worker.queue.name;
39
- const deadLetter = deadLetterQueueName(name);
40
- if (replaceWorker) {
36
+ async function registerQueue(client, registration, context, replaceWorker) {
37
+ const queue = registration._tag === "QueueWorker" ? registration.queue : registration;
38
+ const name = queue.name;
39
+ if (replaceWorker && registration._tag === "QueueWorker") {
41
40
  await client.offWork(name);
42
41
  }
43
- await client.createQueue(deadLetter);
44
- await client.createQueue(name, {
45
- ...queueOptions(worker.queue.queueOptions),
46
- deadLetter,
47
- });
48
- await client.work(name, worker.queue.workerOptions, async (jobs) => {
42
+ await ensureQueue(client, name, queue.queueOptions);
43
+ if (registration._tag === "QueueDefinition") {
44
+ return;
45
+ }
46
+ await client.work(name, queue.workerOptions, async (jobs) => {
49
47
  for (const job of jobs) {
50
- await runQueueWorker(worker, job, context);
48
+ await runQueueWorker(registration, job, context);
51
49
  }
52
50
  });
53
51
  }
54
52
  async function registerSchedule(client, worker, context, replaceWorker) {
55
53
  const { schedule } = worker;
56
- const deadLetter = deadLetterQueueName(schedule.name);
57
54
  if (replaceWorker) {
58
55
  await client.offWork(schedule.name);
59
56
  }
60
- await client.createQueue(deadLetter);
61
- await client.createQueue(schedule.name, {
62
- ...queueOptions(schedule.queueOptions),
63
- deadLetter,
64
- });
57
+ await ensureQueue(client, schedule.name, schedule.queueOptions);
65
58
  await client.work(schedule.name, schedule.workerOptions, async (jobs) => {
66
59
  for (const job of jobs) {
67
60
  await Effect.runPromise(Effect.provide(worker.effect, context), {
@@ -79,12 +72,12 @@ export const registrationNames = (registrations) => {
79
72
  return names;
80
73
  };
81
74
  export const registerJobs = (client, registrations, context, replaceWorkers) => Effect.tryPromise({
82
- catch: (error) => toPgBossError("register", error),
75
+ catch: (error) => (error instanceof PgBossQueueOptionsError ? error : toPgBossError("register", error)),
83
76
  try: async () => {
84
77
  registrationNames(registrations);
85
78
  const provided = workerContext(context);
86
79
  for (const registration of registrations) {
87
- if (isQueueWorker(registration)) {
80
+ if (isQueueWorker(registration) || isQueueDefinition(registration)) {
88
81
  await registerQueue(client, registration, provided, replaceWorkers);
89
82
  }
90
83
  else if (isScheduledWorker(registration)) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/server/internal/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhE,OAAO,EAAwB,UAAU,EAAgE,MAAM,gBAAgB,CAAC;AAChI,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,SAAS,aAAa,CAAC,YAA6B;IACnD,OAAO,YAAY,CAAC,IAAI,KAAK,aAAa,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,YAA6B;IACvD,OAAO,YAAY,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAChD,CAAC;AAED,SAAS,iBAAiB,CAAC,YAA6B;IACvD,OAAO,YAAY,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAA6B,EAAU,EAAE;IACzE,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,OAAO,YAAY,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,IAAI,aAAa,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;IAChC,CAAC;IACD,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;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