@shivaedev/effect-pg-boss 0.13.0 → 0.14.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.14.0 - 2026-10-19
4
+
5
+ ### Added
6
+
7
+ - The jobs service lists a queue's failed jobs with `failedJobs(queue, { limit, cursor })` and the jobs in its dead-letter queue with `deadLetteredJobs(queue, { limit, cursor })`, newest first in pages with an opaque cursor. Each entry carries the job's ID, queue, state, attempt and retry counts, UTC times, the output pg-boss stored, and `data` decoded by the queue's Schema; invalid stored data fails with `PgBossPayloadError`. Dead-letter entries add the original job's ID and error. A failed entry's ID can be passed to `retry`.
8
+
3
9
  ## 0.13.0 - 2026-10-19
4
10
 
5
11
  ### Added
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, look up or retry a job, or read queue health and live counts.
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, read queue health and live counts, or list failed and dead-lettered jobs.
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
 
@@ -318,6 +318,33 @@ export const inspectEmail = (id: string) => Effect.gen(function* () {
318
318
 
319
319
  `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.
320
320
 
321
+ ### List failed and dead-lettered jobs
322
+
323
+ ```ts
324
+ import { Effect, Option } from "effect";
325
+ import { SendEmail } from "./jobs.ts";
326
+ import { Jobs } from "./services.ts";
327
+
328
+ export const failedEmails = (cursor?: string) => Effect.gen(function* () {
329
+ const jobs = yield* Jobs;
330
+ const failed = yield* jobs.failedJobs(SendEmail, { cursor, limit: 20 });
331
+ const deadLettered = yield* jobs.deadLetteredJobs(SendEmail, { limit: 20 });
332
+ return {
333
+ deadLettered: deadLettered.jobs.map((job) => ({ id: job.id, original: Option.getOrNull(job.sourceId), error: job.sourceOutput })),
334
+ failed: failed.jobs.map((job) => ({ id: job.id, attempt: job.attempt, error: job.output, userId: job.data.userId })),
335
+ next: Option.getOrUndefined(failed.next),
336
+ };
337
+ });
338
+ ```
339
+
340
+ `health` and `counts` say how many jobs failed; these two listings say which ones and why. `failedJobs(queue, options)` lists the queue's jobs in the `failed` state, the ones that used up their retries. `deadLetteredJobs(queue, options)` lists every job in the queue's dead-letter queue. Dead-letter entries live in the `-dlq` queue: each is a new job with its own ID that pg-boss copied there when the original failed for good. Both listings read pg-boss's `job` table on each call, through the jobs Layer's own pg-boss connection and in its configured schema, so applications never query pg-boss tables themselves. A custom client needs the native `getDb` capability for them.
341
+
342
+ Each page holds at most `limit` jobs, newest first by creation time; a dead-letter copy is created when its original fails for good. `limit` must be a positive integer. When more jobs remain, `next` is `Some` opaque cursor; pass it back as `cursor` for the following page, and stop when `next` is `None`. Paging continues from the last job it returned, so jobs that fail while you page appear in a fresh listing instead of shifting later pages, and no job appears twice. A malformed cursor or limit fails with `PgBossError` whose `operation` names the listing.
343
+
344
+ An entry carries the job's `id`, `queue`, native `state`, `retryCount`, `retryLimit` and `attempt`, the one-based number of its last started attempt (zero for a job that never started). `createdOn` is a UTC `DateTime`; `startedOn` and `completedOn` are `Option`s of UTC `DateTime`s. `output` is the job's stored output as pg-boss recorded it: for a failed job, the error its last attempt failed with, and `null` when pg-boss stored none. `data` is decoded by the queue's Schema, including traced payloads; invalid stored data fails the listing with `PgBossPayloadError`, as `getJob` does, and the Effect requires the Schema's decoding services. A dead-letter entry adds `sourceId`, the original job's ID as an `Option`, and `sourceOutput`, the error the original failed with. The copy has not run, so its own `output` stays `null` and its `attempt` is zero.
345
+
346
+ Pass a failed entry's `id` to `retry(queue, id)` to run that job again under its original ID; once it completes it leaves the failed listing. Dead-letter IDs belong to the `-dlq` queue, so `retry(queue, id)` does not find them and leaves them unchanged.
347
+
321
348
  ### Queue settings on startup
322
349
 
323
350
  `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.
@@ -441,14 +468,14 @@ Import the module that defines the name; the package has no root entry.
441
468
  | `@shivaedev/effect-pg-boss/server/definition.ts` | `defineQueue`, `defineSchedule`, `jobContext`, `RetryAt`; `DefineQueueOptions`, `DefineScheduleOptions`, `JobContext`, `JobPayloadSchema`, `JobRegistration`, `QueueDefinition`, `QueueOptions`, `QueuePolicy`, `QueueWorker`, `RegistrationRequirements`, `ScheduleDefinition`, `ScheduledWorker` |
442
469
  | `@shivaedev/effect-pg-boss/server/service.ts` | `makePgBoss`; `PgBossDefinition`, `PgBossLayerOptions`, `PgBossService` |
443
470
  | `@shivaedev/effect-pg-boss/server/schema.ts` | `installPgBossSchema`; `PgBossSchemaOptions` |
444
- | `@shivaedev/effect-pg-boss/server/health.ts` | `deadLetterQueueName`; `JobsHealth`, `QueueCounts`, `QueueHealth` |
471
+ | `@shivaedev/effect-pg-boss/server/health.ts` | `deadLetterQueueName`; `DeadLetteredJob`, `JobPage`, `JobPageOptions`, `JobsHealth`, `ListedJob`, `QueueCounts`, `QueueHealth` |
445
472
  | `@shivaedev/effect-pg-boss/server/error.ts` | `PgBossError`, `PgBossPayloadError`, `PgBossQueueOptionsError`, `PgBossTestingError`, `toPgBossError`; `PgBossOperation` |
446
473
  | `@shivaedev/effect-pg-boss/server/client.ts` | `defaultClientFactory`; `PgBossClient`, `PgBossClientFactory` |
447
474
  | `@shivaedev/effect-pg-boss/server/testing.ts` | `makePgBossTesting`, `testRetryPolicy`; `PgBossTesting`, `PgBossTestingOptions` |
448
475
 
449
476
  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`.
450
477
 
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.
478
+ `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 listings, deferral and reconciliation; a requested operation fails with `PgBossError` if its required capability is absent.
452
479
 
453
480
  `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.
454
481
 
@@ -1,5 +1,5 @@
1
1
  import { Redacted } from "effect";
2
- export type PgBossOperation = "counts" | "enqueue" | "getJob" | "health" | "install" | "register" | "retry" | "start" | "stop";
2
+ export type PgBossOperation = "counts" | "deadLetteredJobs" | "enqueue" | "failedJobs" | "getJob" | "health" | "install" | "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>;
@@ -1 +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,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;;;;AAE/H,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;IAED,IAAa,OAAO,IAAI,MAAM,CAG7B;CACD;;;;AAUD,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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AC,QAAQ,CAAC,CAAC,EAAE,CAAC;IACpG,CAAC;CACD;AAED,SAAS,YAAY,CAAC,QAAiB;IACtC,IAAI,CAAC,CAAC,QAAQ,YAAY,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,OAAO,QAAQ,CAAC;IACxB,CAAC;IACD,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACpD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC;AACtG,CAAC;AAED,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,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,5 @@
1
+ import type { DateTime, Option } from "effect";
2
+ import type { JobWithMetadata } from "pg-boss";
1
3
  export interface QueueCounts {
2
4
  readonly activeCount: number;
3
5
  readonly failedCount: number;
@@ -21,4 +23,29 @@ export interface JobsHealth {
21
23
  readonly readyTotal: number;
22
24
  }
23
25
  export declare const deadLetterQueueName: (queueName: string) => string;
26
+ export interface ListedJob<TData> {
27
+ readonly attempt: number;
28
+ readonly completedOn: Option.Option<DateTime.Utc>;
29
+ readonly createdOn: DateTime.Utc;
30
+ readonly data: TData;
31
+ readonly id: string;
32
+ readonly output: unknown;
33
+ readonly queue: string;
34
+ readonly retryCount: number;
35
+ readonly retryLimit: number;
36
+ readonly startedOn: Option.Option<DateTime.Utc>;
37
+ readonly state: JobWithMetadata["state"];
38
+ }
39
+ export interface DeadLetteredJob<TData> extends ListedJob<TData> {
40
+ readonly sourceId: Option.Option<string>;
41
+ readonly sourceOutput: unknown;
42
+ }
43
+ export interface JobPageOptions {
44
+ readonly cursor?: string | undefined;
45
+ readonly limit: number;
46
+ }
47
+ export interface JobPage<TJob> {
48
+ readonly jobs: readonly TJob[];
49
+ readonly next: Option.Option<string>;
50
+ }
24
51
  //# sourceMappingURL=health.d.ts.map
@@ -1 +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,iB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,MAAM,CAAC,CAAC;CACrC"}
@@ -1 +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"}
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AA4BA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,GAAG,SAAS,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { PgBossClient } from "#client.ts";
2
+ import type { PgBossService } from "#service.ts";
3
+ export declare function failedJobsFor(client: PgBossClient, schema: string): PgBossService["failedJobs"];
4
+ export declare function deadLetteredJobsFor(client: PgBossClient, schema: string): PgBossService["deadLetteredJobs"];
5
+ //# sourceMappingURL=listJobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listJobs.d.ts","sourceRoot":"","sources":["../../../src/server/internal/listJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAwBjD,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAK/F;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAE3G"}
@@ -0,0 +1,69 @@
1
+ import { Effect, Option, Redacted, Schema } from "effect";
2
+ import { PgBossPayloadError, toPgBossError } from "#error.ts";
3
+ import { deadLetterQueueName } from "#health.ts";
4
+ import { payloadOf } from "#internal/tracing.ts";
5
+ const Cursor = Schema.StringFromBase64Url.pipe(Schema.decodeTo(Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String]))));
6
+ const Row = Schema.Struct({
7
+ completedOn: Schema.OptionFromNullOr(Schema.DateTimeUtcFromDate),
8
+ createdOn: Schema.DateTimeUtcFromDate,
9
+ cursorAt: Schema.String,
10
+ data: Schema.Unknown,
11
+ id: Schema.String,
12
+ output: Schema.Unknown,
13
+ queue: Schema.String,
14
+ retryCount: Schema.Number,
15
+ retryLimit: Schema.Number,
16
+ sourceId: Schema.OptionFromNullOr(Schema.String),
17
+ sourceOutput: Schema.Unknown,
18
+ startedOn: Schema.OptionFromNullOr(Schema.DateTimeUtcFromDate),
19
+ state: Schema.Literals(["created", "retry", "active", "completed", "cancelled", "failed"]),
20
+ });
21
+ const Rows = Schema.Array(Row);
22
+ export function failedJobsFor(client, schema) {
23
+ return (queue, options) => listJobs(client, schema, "failedJobs", queue, options).pipe(Effect.map(({ jobs, next }) => ({ jobs: jobs.map(({ sourceId: _id, sourceOutput: _output, ...job }) => job), next })));
24
+ }
25
+ export function deadLetteredJobsFor(client, schema) {
26
+ return (queue, options) => listJobs(client, schema, "deadLetteredJobs", queue, options);
27
+ }
28
+ function listJobs(client, schema, listing, queue, options) {
29
+ return Effect.tryPromise({
30
+ catch: (error) => toPgBossError(listing, error, queue.name),
31
+ try: async () => {
32
+ if (client.getDb === undefined) {
33
+ throw new TypeError("This pg-boss client does not support getDb");
34
+ }
35
+ if (!Number.isSafeInteger(options.limit) || options.limit < 1) {
36
+ throw new RangeError("The page limit must be a positive integer");
37
+ }
38
+ const after = options.cursor === undefined ? undefined : await Schema.decodeUnknownPromise(Cursor)(options.cursor);
39
+ const quotedSchema = `"${schema.replaceAll('"', '""')}"`;
40
+ const { rows } = await client.getDb().executeSql(`SELECT
41
+ id,
42
+ name AS queue,
43
+ state,
44
+ retry_count AS "retryCount",
45
+ retry_limit AS "retryLimit",
46
+ created_on AS "createdOn",
47
+ started_on AS "startedOn",
48
+ completed_on AS "completedOn",
49
+ output,
50
+ data,
51
+ source_id AS "sourceId",
52
+ source_output AS "sourceOutput",
53
+ to_json(created_on) #>> '{}' AS "cursorAt"
54
+ FROM ${quotedSchema}.job
55
+ WHERE name = $1
56
+ ${listing === "failedJobs" ? "AND state = 'failed'" : ""}
57
+ AND ($2::timestamptz IS NULL OR (created_on, id) < ($2::timestamptz, $3::uuid))
58
+ ORDER BY created_on DESC, id DESC
59
+ LIMIT $4`, [listing === "failedJobs" ? queue.name : deadLetterQueueName(queue.name), after?.[0] ?? null, after?.[1] ?? null, options.limit + 1]);
60
+ return Schema.decodeUnknownPromise(Rows)(rows);
61
+ },
62
+ }).pipe(Effect.flatMap((rows) => {
63
+ const page = rows.slice(0, options.limit);
64
+ const last = page.at(-1);
65
+ const next = rows.length > options.limit && last !== undefined ? Option.some(Schema.encodeSync(Cursor)([last.cursorAt, last.id])) : Option.none();
66
+ return Effect.forEach(page, ({ cursorAt: _, data, ...row }) => Schema.decodeUnknownEffect(queue.schema)(payloadOf(data)).pipe(Effect.mapError((error) => new PgBossPayloadError({ direction: "decode", original: Redacted.make(error), queue: queue.name })), Effect.map((decoded) => ({ ...row, attempt: Option.isSome(row.startedOn) ? row.retryCount + 1 : 0, data: decoded })))).pipe(Effect.map((jobs) => ({ jobs, next })));
67
+ }));
68
+ }
69
+ //# sourceMappingURL=listJobs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listJobs.js","sourceRoot":"","sources":["../../../src/server/internal/listJobs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG1D,OAAO,EAAoB,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAwB,mBAAmB,EAAqC,MAAM,YAAY,CAAC;AAC1G,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC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C,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAC7D,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,EAC9H,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CACpH,CACD,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/server/internal/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,WAAW,WAAY,YAAY,SAAS,SAAS,MAAM,EAAE,sBAAsB,aAoC9F,CAAC"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/server/internal/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,WAAW,WAAY,YAAY,SAAS,SAAS,MAAM,EAAE,sBAAsB,aAsC9F,CAAC"}
@@ -3,9 +3,11 @@ import { PgBossPayloadError, toPgBossError } from "#error.ts";
3
3
  import { countsFor } from "#internal/countsFor.ts";
4
4
  import { healthFor } from "#internal/health.ts";
5
5
  import { getJobFor, retryFor } from "#internal/jobControl.ts";
6
+ import { deadLetteredJobsFor, failedJobsFor } from "#internal/listJobs.ts";
6
7
  import { capturePayload } from "#internal/tracing.ts";
7
8
  export const makeService = (client, names, schema = "pgboss") => ({
8
9
  counts: (queue) => countsFor(client, schema, queue.name),
10
+ deadLetteredJobs: deadLetteredJobsFor(client, schema),
9
11
  enqueue: (queue, payload, options) => Schema.encodeUnknownEffect(queue.schema)(payload).pipe(Effect.mapError((error) => new PgBossPayloadError({
10
12
  direction: "encode",
11
13
  original: Redacted.make(error),
@@ -23,6 +25,7 @@ export const makeService = (client, names, schema = "pgboss") => ({
23
25
  try: () => client.send(queue.name, data, queue.key === undefined ? options : { ...options, singletonKey: queue.key(payload) }),
24
26
  })), Effect.map(Option.fromNullishOr));
25
27
  })),
28
+ failedJobs: failedJobsFor(client, schema),
26
29
  getJob: getJobFor(client),
27
30
  health: healthFor(client, names),
28
31
  retry: retryFor(client),
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/server/internal/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EAAoB,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,M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AO,CAAC,EAAE,CAAC;SAC9H,CAAC,CACF,EACD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAChC,CAAC;IACH,CAAC,CAAC,CACF;IACF,UAAU,EAAE,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;IACzC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC;IAChC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;CACvB,CAAC,CAAC"}
@@ -3,12 +3,14 @@ import type { ConstructorOptions, JobWithMetadata, SendOptions, StopOptions } fr
3
3
  import type { PgBossClientFactory } from "#client.ts";
4
4
  import type { JobPayloadSchema, JobRegistration, QueueDefinition, RegistrationRequirements } from "#definition.ts";
5
5
  import type { PgBossError, PgBossPayloadError, PgBossQueueOptionsError } from "#error.ts";
6
- import type { JobsHealth, QueueCounts } from "#health.ts";
6
+ import type { DeadLetteredJob, JobPage, JobPageOptions, JobsHealth, ListedJob, QueueCounts } from "#health.ts";
7
7
  export interface PgBossService {
8
8
  readonly counts: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<QueueCounts, PgBossError>;
9
+ readonly deadLetteredJobs: <const TName extends string, const TPayload extends JobPayloadSchema>(queue: QueueDefinition<TName, TPayload>, options: JobPageOptions) => Effect.Effect<JobPage<DeadLetteredJob<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]>;
9
10
  readonly enqueue: <const TName extends string, const TPayload extends JobPayloadSchema, const TQueue extends QueueDefinition<TName, TPayload>>(queue: QueueDefinition<TName, TPayload> & TQueue, payload: NoInfer<Schema.Schema.Type<TPayload>>, options?: NoInfer<TQueue["key"] extends undefined ? SendOptions : Omit<SendOptions, "singletonKey"> & {
10
11
  readonly singletonKey?: never;
11
12
  }>) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, TPayload["EncodingServices"]>;
13
+ readonly failedJobs: <const TName extends string, const TPayload extends JobPayloadSchema>(queue: QueueDefinition<TName, TPayload>, options: JobPageOptions) => Effect.Effect<JobPage<ListedJob<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]>;
12
14
  readonly getJob: <const TName extends string, const TPayload extends JobPayloadSchema>(queue: QueueDefinition<TName, TPayload>, id: string) => Effect.Effect<Option.Option<JobWithMetadata<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]>;
13
15
  readonly health: Effect.Effect<JobsHealth, PgBossError>;
14
16
  readonly retry: (queue: Pick<QueueDefinition, "name">, id: string) => Effect.Effect<void, PgBossError>;
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/server/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACnH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAM1D,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IACnG,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,KA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AM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/effect-pg-boss",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Effect-native jobs and lifecycle management for pg-boss",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/effect-pg-boss#readme",
6
6
  "bugs": {
@@ -42,8 +42,8 @@
42
42
  ],
43
43
  "devDependencies": {
44
44
  "@shivaedev/effect-test": "0.7.1",
45
- "@shivaedev/effect-test-sql": "0.8.0",
46
- "@shivaedev/quality": "0.30.0",
45
+ "@shivaedev/effect-test-sql": "0.8.1",
46
+ "@shivaedev/quality": "0.31.0",
47
47
  "@shivaedev/test-story": "0.17.0",
48
48
  "@types/node": "24.19.2",
49
49
  "effect": "4.0.4",
@@ -1,6 +1,17 @@
1
1
  import { Data, Redacted } from "effect";
2
2
 
3
- export type PgBossOperation = "counts" | "enqueue" | "getJob" | "health" | "install" | "register" | "retry" | "start" | "stop";
3
+ export type PgBossOperation =
4
+ | "counts"
5
+ | "deadLetteredJobs"
6
+ | "enqueue"
7
+ | "failedJobs"
8
+ | "getJob"
9
+ | "health"
10
+ | "install"
11
+ | "register"
12
+ | "retry"
13
+ | "start"
14
+ | "stop";
4
15
 
5
16
  export class PgBossError extends Data.TaggedError("PgBossError")<{
6
17
  readonly operation: PgBossOperation;
@@ -1,3 +1,6 @@
1
+ import type { DateTime, Option } from "effect";
2
+ import type { JobWithMetadata } from "pg-boss";
3
+
1
4
  export interface QueueCounts {
2
5
  readonly activeCount: number;
3
6
  readonly failedCount: number;
@@ -24,3 +27,32 @@ export interface JobsHealth {
24
27
  }
25
28
 
26
29
  export const deadLetterQueueName = (queueName: string): string => `${queueName}-dlq`;
30
+
31
+ export interface ListedJob<TData> {
32
+ readonly attempt: number;
33
+ readonly completedOn: Option.Option<DateTime.Utc>;
34
+ readonly createdOn: DateTime.Utc;
35
+ readonly data: TData;
36
+ readonly id: string;
37
+ readonly output: unknown;
38
+ readonly queue: string;
39
+ readonly retryCount: number;
40
+ readonly retryLimit: number;
41
+ readonly startedOn: Option.Option<DateTime.Utc>;
42
+ readonly state: JobWithMetadata["state"];
43
+ }
44
+
45
+ export interface DeadLetteredJob<TData> extends ListedJob<TData> {
46
+ readonly sourceId: Option.Option<string>;
47
+ readonly sourceOutput: unknown;
48
+ }
49
+
50
+ export interface JobPageOptions {
51
+ readonly cursor?: string | undefined;
52
+ readonly limit: number;
53
+ }
54
+
55
+ export interface JobPage<TJob> {
56
+ readonly jobs: readonly TJob[];
57
+ readonly next: Option.Option<string>;
58
+ }
@@ -0,0 +1,99 @@
1
+ import { Effect, Option, Redacted, Schema } from "effect";
2
+ import type { PgBossClient } from "#client.ts";
3
+ import type { JobPayloadSchema, QueueDefinition } from "#definition.ts";
4
+ import { type PgBossError, PgBossPayloadError, toPgBossError } from "#error.ts";
5
+ import { type DeadLetteredJob, deadLetterQueueName, type JobPage, type JobPageOptions } from "#health.ts";
6
+ import { payloadOf } from "#internal/tracing.ts";
7
+ import type { PgBossService } from "#service.ts";
8
+
9
+ const Cursor = Schema.StringFromBase64Url.pipe(Schema.decodeTo(Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String]))));
10
+
11
+ const Row = Schema.Struct({
12
+ completedOn: Schema.OptionFromNullOr(Schema.DateTimeUtcFromDate),
13
+ createdOn: Schema.DateTimeUtcFromDate,
14
+ cursorAt: Schema.String,
15
+ data: Schema.Unknown,
16
+ id: Schema.String,
17
+ output: Schema.Unknown,
18
+ queue: Schema.String,
19
+ retryCount: Schema.Number,
20
+ retryLimit: Schema.Number,
21
+ sourceId: Schema.OptionFromNullOr(Schema.String),
22
+ sourceOutput: Schema.Unknown,
23
+ startedOn: Schema.OptionFromNullOr(Schema.DateTimeUtcFromDate),
24
+ state: Schema.Literals(["created", "retry", "active", "completed", "cancelled", "failed"]),
25
+ });
26
+
27
+ const Rows = Schema.Array(Row);
28
+
29
+ type Listing = "deadLetteredJobs" | "failedJobs";
30
+
31
+ export function failedJobsFor(client: PgBossClient, schema: string): PgBossService["failedJobs"] {
32
+ return (queue, options) =>
33
+ listJobs(client, schema, "failedJobs", queue, options).pipe(
34
+ Effect.map(({ jobs, next }) => ({ jobs: jobs.map(({ sourceId: _id, sourceOutput: _output, ...job }) => job), next })),
35
+ );
36
+ }
37
+
38
+ export function deadLetteredJobsFor(client: PgBossClient, schema: string): PgBossService["deadLetteredJobs"] {
39
+ return (queue, options) => listJobs(client, schema, "deadLetteredJobs", queue, options);
40
+ }
41
+
42
+ function listJobs<const TName extends string, const TPayload extends JobPayloadSchema>(
43
+ client: PgBossClient,
44
+ schema: string,
45
+ listing: Listing,
46
+ queue: QueueDefinition<TName, TPayload>,
47
+ options: JobPageOptions,
48
+ ): Effect.Effect<JobPage<DeadLetteredJob<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]> {
49
+ return Effect.tryPromise({
50
+ catch: (error) => toPgBossError(listing, error, queue.name),
51
+ try: async () => {
52
+ if (client.getDb === undefined) {
53
+ throw new TypeError("This pg-boss client does not support getDb");
54
+ }
55
+ if (!Number.isSafeInteger(options.limit) || options.limit < 1) {
56
+ throw new RangeError("The page limit must be a positive integer");
57
+ }
58
+ const after = options.cursor === undefined ? undefined : await Schema.decodeUnknownPromise(Cursor)(options.cursor);
59
+ const quotedSchema = `"${schema.replaceAll('"', '""')}"`;
60
+ const { rows } = await client.getDb().executeSql(
61
+ `SELECT
62
+ id,
63
+ name AS queue,
64
+ state,
65
+ retry_count AS "retryCount",
66
+ retry_limit AS "retryLimit",
67
+ created_on AS "createdOn",
68
+ started_on AS "startedOn",
69
+ completed_on AS "completedOn",
70
+ output,
71
+ data,
72
+ source_id AS "sourceId",
73
+ source_output AS "sourceOutput",
74
+ to_json(created_on) #>> '{}' AS "cursorAt"
75
+ FROM ${quotedSchema}.job
76
+ WHERE name = $1
77
+ ${listing === "failedJobs" ? "AND state = 'failed'" : ""}
78
+ AND ($2::timestamptz IS NULL OR (created_on, id) < ($2::timestamptz, $3::uuid))
79
+ ORDER BY created_on DESC, id DESC
80
+ LIMIT $4`,
81
+ [listing === "failedJobs" ? queue.name : deadLetterQueueName(queue.name), after?.[0] ?? null, after?.[1] ?? null, options.limit + 1],
82
+ );
83
+ return Schema.decodeUnknownPromise(Rows)(rows);
84
+ },
85
+ }).pipe(
86
+ Effect.flatMap((rows) => {
87
+ const page = rows.slice(0, options.limit);
88
+ const last = page.at(-1);
89
+ const next =
90
+ rows.length > options.limit && last !== undefined ? Option.some(Schema.encodeSync(Cursor)([last.cursorAt, last.id])) : Option.none();
91
+ return Effect.forEach(page, ({ cursorAt: _, data, ...row }) =>
92
+ Schema.decodeUnknownEffect(queue.schema)(payloadOf(data)).pipe(
93
+ Effect.mapError((error) => new PgBossPayloadError({ direction: "decode", original: Redacted.make(error), queue: queue.name })),
94
+ Effect.map((decoded) => ({ ...row, attempt: Option.isSome(row.startedOn) ? row.retryCount + 1 : 0, data: decoded })),
95
+ ),
96
+ ).pipe(Effect.map((jobs) => ({ jobs, next })));
97
+ }),
98
+ );
99
+ }
@@ -4,11 +4,13 @@ import { type PgBossError, PgBossPayloadError, toPgBossError } from "#error.ts";
4
4
  import { countsFor } from "#internal/countsFor.ts";
5
5
  import { healthFor } from "#internal/health.ts";
6
6
  import { getJobFor, retryFor } from "#internal/jobControl.ts";
7
+ import { deadLetteredJobsFor, failedJobsFor } from "#internal/listJobs.ts";
7
8
  import { capturePayload } from "#internal/tracing.ts";
8
9
  import type { PgBossService } from "#service.ts";
9
10
 
10
11
  export const makeService = (client: PgBossClient, names: readonly string[], schema = "pgboss"): PgBossService => ({
11
12
  counts: (queue) => countsFor(client, schema, queue.name),
13
+ deadLetteredJobs: deadLetteredJobsFor(client, schema),
12
14
  enqueue: (queue, payload, options) =>
13
15
  Schema.encodeUnknownEffect(queue.schema)(payload).pipe(
14
16
  Effect.mapError(
@@ -40,6 +42,7 @@ export const makeService = (client: PgBossClient, names: readonly string[], sche
40
42
  );
41
43
  }),
42
44
  ),
45
+ failedJobs: failedJobsFor(client, schema),
43
46
  getJob: getJobFor(client),
44
47
  health: healthFor(client, names),
45
48
  retry: retryFor(client),
@@ -3,7 +3,7 @@ import type { ConstructorOptions, JobWithMetadata, SendOptions, StopOptions } fr
3
3
  import type { PgBossClientFactory } from "#client.ts";
4
4
  import type { JobPayloadSchema, JobRegistration, QueueDefinition, RegistrationRequirements } from "#definition.ts";
5
5
  import type { PgBossError, PgBossPayloadError, PgBossQueueOptionsError } from "#error.ts";
6
- import type { JobsHealth, QueueCounts } from "#health.ts";
6
+ import type { DeadLetteredJob, JobPage, JobPageOptions, JobsHealth, ListedJob, QueueCounts } from "#health.ts";
7
7
  import { logClientError, subscribeClientErrors } from "#internal/clientErrors.ts";
8
8
  import { acquireClient, releaseClient } from "#internal/lifecycle.ts";
9
9
  import { registerJobs, registrationName } from "#internal/register.ts";
@@ -11,11 +11,19 @@ import { makeService } from "#internal/service.ts";
11
11
 
12
12
  export interface PgBossService {
13
13
  readonly counts: (queue: Pick<QueueDefinition, "name">) => Effect.Effect<QueueCounts, PgBossError>;
14
+ readonly deadLetteredJobs: <const TName extends string, const TPayload extends JobPayloadSchema>(
15
+ queue: QueueDefinition<TName, TPayload>,
16
+ options: JobPageOptions,
17
+ ) => Effect.Effect<JobPage<DeadLetteredJob<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]>;
14
18
  readonly enqueue: <const TName extends string, const TPayload extends JobPayloadSchema, const TQueue extends QueueDefinition<TName, TPayload>>(
15
19
  queue: QueueDefinition<TName, TPayload> & TQueue,
16
20
  payload: NoInfer<Schema.Schema.Type<TPayload>>,
17
21
  options?: NoInfer<TQueue["key"] extends undefined ? SendOptions : Omit<SendOptions, "singletonKey"> & { readonly singletonKey?: never }>,
18
22
  ) => Effect.Effect<Option.Option<string>, PgBossError | PgBossPayloadError, TPayload["EncodingServices"]>;
23
+ readonly failedJobs: <const TName extends string, const TPayload extends JobPayloadSchema>(
24
+ queue: QueueDefinition<TName, TPayload>,
25
+ options: JobPageOptions,
26
+ ) => Effect.Effect<JobPage<ListedJob<TPayload["Type"]>>, PgBossError | PgBossPayloadError, TPayload["DecodingServices"]>;
19
27
  readonly getJob: <const TName extends string, const TPayload extends JobPayloadSchema>(
20
28
  queue: QueueDefinition<TName, TPayload>,
21
29
  id: string,