@shivaedev/effect-pg-boss 0.6.1 → 0.7.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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 - 2026-10-17
4
+
5
+ ### Changed
6
+
7
+ - Queue and schedule workers default to native pg-boss `batchSize: 10` and `burstWhenBatchFull: true`, draining full batches immediately instead of waiting for the notification polling backstop. Native worker options still override the defaults, including batch size and local concurrency. Handlers run sequentially within each batch; pg-boss retries a rejected batch together.
8
+
9
+ ### Fixed
10
+
11
+ - `PgBossDefinition.layer` supplies its own jobs service to queue handlers and scheduled effects through the scoped Effect context. Handlers can enqueue follow-ups to worker or producer-only queues using that same client. Only the owning identifier is removed from the Layer's input requirements; other services remain typed. Startup creates every declared queue before starting consumers.
12
+
3
13
  ## 0.6.1 - 2026-10-17
4
14
 
5
15
  ### Fixed
package/README.md CHANGED
@@ -99,6 +99,23 @@ The schedule runs a payload-free Effect. This schedule registers its cron expres
99
99
 
100
100
  The Layer requires the workers' Effect services. Leaving `Mail` unprovided leaves that requirement in the resulting Effect's type. A primitive Schema such as `Schema.String` is rejected as a queue definition because the durable contract must be an object.
101
101
 
102
+ ### Backlog throughput and concurrency
103
+
104
+ Queue and schedule workers default to `batchSize: 10` and `burstWhenBatchFull: true`. pg-boss fetches again immediately after a full batch completes, until a fetch returns fewer than ten jobs. The adapter runs handlers sequentially within each batch, and pg-boss defaults `localConcurrency` to one. Set native `localConcurrency` to run multiple batches at once:
105
+
106
+ ```ts
107
+ const Compare = defineQueue({
108
+ name: "compare",
109
+ schema: Schema.Struct({ id: Schema.Number }),
110
+ queue: { notify: true },
111
+ worker: { batchSize: 2, localConcurrency: 5 },
112
+ });
113
+ ```
114
+
115
+ This worker runs up to five handlers at once. `worker` accepts pg-boss 12's `WorkOptions`, including `batchSize`, `localConcurrency`, `pollingIntervalSeconds`, `notifyPollingIntervalSeconds` and the burst options. Explicit options override the adapter defaults. pg-boss ignores `burstWhenBatchFull` at `batchSize: 1`; keep a batch size of at least two for immediate backlog draining. A failed handler rejects its batch, so pg-boss can retry earlier jobs in that batch; handlers must tolerate repeated side effects.
116
+
117
+ 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. Override the backstop only when the application needs a different bound for work that becomes runnable without a notification, such as delayed jobs or retries. The PostgreSQL backlog tests insert 30 jobs at once and verify completion within 2.5 seconds with both defaults and configured batches and concurrency.
118
+
102
119
  ### Once per runtime: provide the workers
103
120
 
104
121
  Build the jobs Layer in `runtime.ts`:
@@ -243,6 +260,33 @@ export const producerLayer = (databaseUrl: string) =>
243
260
 
244
261
  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.
245
262
 
263
+ ### Enqueue follow-ups from a handler
264
+
265
+ A handler can yield the same `Jobs` service that owns it. The Layer supplies that service from its scoped client; other handler and Schema service requirements remain required inputs to the Layer.
266
+
267
+ ```ts
268
+ const Receipt = defineQueue({
269
+ name: "receipt",
270
+ schema: Schema.Struct({ userId: Schema.Number }),
271
+ });
272
+
273
+ const sendAndQueueReceipt = SendEmail.handle(({ userId }) =>
274
+ Effect.gen(function* () {
275
+ const mail = yield* Mail;
276
+ yield* mail.send(userId);
277
+ const jobs = yield* Jobs;
278
+ yield* jobs.enqueue(Receipt, { userId });
279
+ }),
280
+ );
281
+
282
+ const live = Jobs.layer({
283
+ connectionString: databaseUrl,
284
+ jobs: [sendAndQueueReceipt, Receipt],
285
+ }).pipe(Layer.provide(MailLive));
286
+ ```
287
+
288
+ Include every target queue in `jobs`, as either a worker or a producer-only definition. Startup creates all queues before starting consumers. The example registers `Receipt` for another process to consume. A follow-up target can also have a worker in the same Layer. Scheduled effects can yield `Jobs` too. Keep one jobs Layer in the process's native Layer graph; that Layer owns one client for enqueueing and handling. The PostgreSQL follow-up test completes a chain across two workers, enqueues to a producer-only queue and asserts one client acquisition and shutdown.
289
+
246
290
  ### API
247
291
 
248
292
  Import the module that defines the name; the package has no root entry.
@@ -267,7 +311,7 @@ The application's service has these operations:
267
311
 
268
312
  `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`.
269
313
 
270
- `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.
314
+ `onError` handles pg-boss client `error` events using the services captured by the Layer. The Layer's requirement type includes the workers' services and their payload Schemas' `DecodingServices`, excluding its own jobs identifier, plus the callback's services. Only the owning jobs service is supplied automatically; a handler using another jobs definition still requires that definition's Layer. `enqueue` includes the payload Schema's `EncodingServices` in its requirement type.
271
315
 
272
316
  `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.
273
317
 
@@ -9,7 +9,7 @@ export const defineQueue = (options) => {
9
9
  name: options.name,
10
10
  queueOptions: Object.freeze({ ...options.queue }),
11
11
  schema: options.schema,
12
- workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
12
+ workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
13
13
  };
14
14
  return Object.freeze(definition);
15
15
  };
@@ -25,7 +25,7 @@ export const defineSchedule = (options) => {
25
25
  schedule: definition,
26
26
  }),
27
27
  scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
28
- workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
28
+ workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
29
29
  };
30
30
  return Object.freeze(definition);
31
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"definition.js","sourceRoot":"","sources":["../../src/server/definition.ts"],"names":[],"mappings":"AAoEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,OAA0C,EACT,EAAE;IACnC,MAAM,UAAU,GAAmC;QAClD,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CACnB,MAAM,CAAC,MAAM,CAAC;YACb,IAAI,EAAE,aAAsB;YAC5B,OAAO;YACP,KAAK,EAAE,UAAU;SACjB,CAAC;QACH,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACjD,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,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;AAUF,MAAM,CAAC,MAAM,cAAc,GAAG,CAA4B,OAAoC,EAA4B,EAAE;IAC3H,MAAM,UAAU,GAA6B;QAC5C,IAAI,EAAE,oBAAoB;Q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AAC,gBAAgB;IACtC,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC"}
@@ -2,7 +2,7 @@ import { type Context, Effect } from "effect";
2
2
  import type { PgBossClient } from "#client.ts";
3
3
  import { type JobRegistration } from "#definition.ts";
4
4
  import { PgBossQueueOptionsError } from "#error.ts";
5
- export declare const registrationName: (registration: JobRegistration) => string;
5
+ export declare function registrationName(registration: JobRegistration): string;
6
6
  export declare const registrationNames: (registrations: readonly JobRegistration[]) => readonly string[];
7
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>;
8
8
  //# sourceMappingURL=register.d.ts.map
@@ -1 +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;AAgBvF,eAAO,MAAM,gBAAgB,iBAAkB,eAAe,KAAG,MAWhE,CAAC;AAsEF,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
+ {"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,EACN,KAAK,eAAe,EAMpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAsB,uBAAuB,EAAiB,MAAM,WAAW,CAAC;AA6BvF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,eAAe,GAAG,MAAM,CAEtE;AAgED,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,CAe7E,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Effect, Redacted, Schema } from "effect";
2
- import { jobContext } from "#definition.ts";
2
+ import { jobContext, } from "#definition.ts";
3
3
  import { PgBossPayloadError, PgBossQueueOptionsError, toPgBossError } from "#error.ts";
4
4
  import { ensureQueue } from "#internal/ensureQueue.ts";
5
5
  import { payloadOf, traceJob } from "#internal/tracing.ts";
@@ -12,18 +12,32 @@ function isScheduledWorker(registration) {
12
12
  function isQueueDefinition(registration) {
13
13
  return registration._tag === "QueueDefinition";
14
14
  }
15
- export const registrationName = (registration) => {
15
+ function registrationDefinition(registration) {
16
16
  if (isQueueDefinition(registration)) {
17
- return registration.name;
17
+ return registration;
18
18
  }
19
19
  if (isQueueWorker(registration)) {
20
- return registration.queue.name;
20
+ return registration.queue;
21
21
  }
22
22
  if (isScheduledWorker(registration)) {
23
- return registration.schedule.name;
23
+ return registration.schedule;
24
24
  }
25
25
  throw new TypeError(`Unknown pg-boss registration: ${registration._tag}`);
26
- };
26
+ }
27
+ export function registrationName(registration) {
28
+ return registrationDefinition(registration).name;
29
+ }
30
+ async function prepareQueues(client, registrations, replaceWorkers) {
31
+ for (const registration of registrations) {
32
+ if (replaceWorkers && !isQueueDefinition(registration)) {
33
+ await client.offWork(registrationName(registration));
34
+ }
35
+ }
36
+ for (const registration of registrations) {
37
+ const definition = registrationDefinition(registration);
38
+ await ensureQueue(client, definition.name, definition.queueOptions);
39
+ }
40
+ }
27
41
  function workerContext(context) {
28
42
  return context;
29
43
  }
@@ -34,13 +48,9 @@ function runQueueWorker(worker, job, context) {
34
48
  queue: worker.queue.name,
35
49
  })), Effect.flatMap((payload) => worker.handler(payload, jobContext(job))), (effect) => traceJob(effect, job, worker.queue.name), Effect.provide(context)), { signal: job.signal });
36
50
  }
37
- async function registerQueue(client, registration, context, replaceWorker) {
51
+ async function registerQueue(client, registration, context) {
38
52
  const queue = registration._tag === "QueueWorker" ? registration.queue : registration;
39
53
  const name = queue.name;
40
- if (replaceWorker && registration._tag === "QueueWorker") {
41
- await client.offWork(name);
42
- }
43
- await ensureQueue(client, name, queue.queueOptions);
44
54
  if (registration._tag === "QueueDefinition") {
45
55
  return;
46
56
  }
@@ -50,12 +60,8 @@ async function registerQueue(client, registration, context, replaceWorker) {
50
60
  }
51
61
  });
52
62
  }
53
- async function registerSchedule(client, worker, context, replaceWorker) {
63
+ async function registerSchedule(client, worker, context) {
54
64
  const { schedule } = worker;
55
- if (replaceWorker) {
56
- await client.offWork(schedule.name);
57
- }
58
- await ensureQueue(client, schedule.name, schedule.queueOptions);
59
65
  await client.work(schedule.name, schedule.workerOptions, async (jobs) => {
60
66
  for (const job of jobs) {
61
67
  await Effect.runPromise(Effect.provide(traceJob(worker.effect, job, schedule.name), context), {
@@ -76,13 +82,14 @@ export const registerJobs = (client, registrations, context, replaceWorkers) =>
76
82
  catch: (error) => (error instanceof PgBossQueueOptionsError ? error : toPgBossError("register", error)),
77
83
  try: async () => {
78
84
  registrationNames(registrations);
85
+ await prepareQueues(client, registrations, replaceWorkers);
79
86
  const provided = workerContext(context);
80
87
  for (const registration of registrations) {
81
88
  if (isQueueWorker(registration) || isQueueDefinition(registration)) {
82
- await registerQueue(client, registration, provided, replaceWorkers);
89
+ await registerQueue(client, registration, provided);
83
90
  }
84
91
  else if (isScheduledWorker(registration)) {
85
- await registerSchedule(client, registration, provided, replaceWorkers);
92
+ await registerSchedule(client, registration, provided);
86
93
  }
87
94
  }
88
95
  },
@@ -1 +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;AACvD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE3D,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,EA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M,YAAY,IAAI,aAAa,EAAE,CAAC;YAC1C,IAAI,aAAa,CAAC,YAAY,CAAC,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;gBACpE,MAAM,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;iBAAM,IAAI,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5C,MAAM,gBAAgB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;YACxD,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAC,CAAC"}
@@ -19,7 +19,7 @@ export type PgBossLayerOptions<TRegistrations extends readonly JobRegistration[]
19
19
  readonly stop?: StopOptions;
20
20
  };
21
21
  export interface PgBossDefinition<TIdentifier extends string = string> extends Context.Service<TIdentifier, PgBossService> {
22
- readonly layer: <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(options: PgBossLayerOptions<TRegistrations, TErrorRequirements>) => Layer.Layer<TIdentifier, PgBossError | PgBossQueueOptionsError, RegistrationRequirements<TRegistrations> | TErrorRequirements>;
22
+ readonly layer: <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(options: PgBossLayerOptions<TRegistrations, TErrorRequirements>) => Layer.Layer<TIdentifier, PgBossError | PgBossQueueOptionsError, Exclude<RegistrationRequirements<TRegistrations>, TIdentifier> | TErrorRequirements>;
23
23
  }
24
24
  export declare const makePgBoss: <const TIdentifier extends string>(identifier: TIdentifier) => PgBossDefinition<TIdentifier>;
25
25
  //# sourceMappingURL=service.d.ts.map
@@ -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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B,CAAC,KAC3D,KAAK,CAAC,KAAK,CACf,WAAW,EACX,WAAW,GAAG,uBAAuB,EACrC,OAAO,CAAC,wBAAwB,CAAC,cAAc,CAAC,EAAE,WAAW,CAAC,GAAG,kBAAkB,CACnF,CAAC;CACF;AAMD,eAAO,MAAM,UAAU,GAAI,KAAK,CAAC,WAAW,SAAS,MAAM,cAAc,WAAW,KAAG,gBAAgB,CAAC,WAAW,CAmDlH,CAAC"}
@@ -11,19 +11,21 @@ export const makePgBoss = (identifier) => {
11
11
  const names = options.jobs.map(registrationName);
12
12
  const { clientFactory, clientCacheKey, jobs, onError, stop, ...constructorOptions } = options;
13
13
  const acquire = Effect.acquireRelease(Effect.gen(function* () {
14
- const context = yield* Effect.context();
14
+ const dependencies = yield* Effect.context();
15
15
  const acquired = yield* acquireClient({
16
16
  clientCacheKey,
17
17
  clientFactory,
18
18
  constructor: constructorOptions,
19
19
  });
20
+ const service = makeService(acquired.client, names, constructorOptions.schema);
21
+ const context = Context.add(dependencies, Service, service);
20
22
  const reportError = onError ?? logClientError;
21
23
  const errorListener = (error) => {
22
24
  void Effect.runPromise(Effect.exit(Effect.provide(reportError(error), context)));
23
25
  };
24
26
  acquired.client.on("error", errorListener);
25
27
  const registration = registerJobs(acquired.client, jobs, context, acquired.reused);
26
- return yield* registration.pipe(Effect.as({ acquired, context, errorListener }), Effect.onError(() => {
28
+ return yield* registration.pipe(Effect.as({ acquired, errorListener, service }), Effect.onError(() => {
27
29
  acquired.client.off("error", errorListener);
28
30
  return releaseClient(acquired, stop);
29
31
  }));
@@ -31,7 +33,7 @@ export const makePgBoss = (identifier) => {
31
33
  resource.acquired.client.off("error", resource.errorListener);
32
34
  return releaseClient(resource.acquired, stop);
33
35
  });
34
- return Layer.effect(Service, Effect.map(acquire, ({ acquired }) => makeService(acquired.client, names, constructorOptions.schema)));
36
+ return Layer.effect(Service, Effect.map(acquire, ({ service }) => service));
35
37
  };
36
38
  return Object.assign(Service, { layer });
37
39
  };
@@ -1 +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M,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAC7C,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1C,CAAC,CAAC"}
package/docs/roadmap.md CHANGED
@@ -9,6 +9,8 @@ This file owns the package's implementation inventory and open API choices. The
9
9
  - [x] Encoding at enqueue and decoding before the handler. The PostgreSQL test round-trips a transformed payload and checks that malformed stored data reaches the dead-letter queue without calling the domain handler.
10
10
  - [x] Queue and schedule registration, with dead-letter queues, default retry settings and UTC schedule registration. Fake-client tests verify the supplied settings and a retry-limit override.
11
11
  - [x] Producer-only queue definitions create queues and dead-letter queues through `Jobs.layer({ jobs: [Queue] })`, without starting a consumer. The [PostgreSQL producer test](../src/server/producerPostgres.spec.ts) enqueues a transformed payload and observes worker retry exhaustion and dead-letter delivery. The [starter producer](../../../examples/starter/src/server/noteProducer.ts) uses this API.
12
+ - [x] Native pg-boss burst defaults (`batchSize: 10`, `burstWhenBatchFull: true`) and configurable batches and local concurrency. [PostgreSQL backlog evidence](../src/server/throughputPostgres.spec.ts) drains 30 jobs within 2.5 seconds.
13
+ - [x] Handlers and scheduled effects can yield their owning jobs service without an external self requirement. [PostgreSQL follow-up evidence](../src/server/followUpPostgres.spec.ts) completes a worker chain and enqueues to a producer-only queue using one scoped client. All declared queues exist before consumers start.
12
14
  - [x] Worker and scheduled Effect service capture. Runtime and packed-consumer type tests preserve handler requirements.
13
15
  - [x] Scoped startup and shutdown, including cleanup when startup or registration fails.
14
16
  - [x] Explicit keyed client reuse and unkeyed per-build acquisition. Lifecycle tests cover two builds sharing one client and replacing the registered worker.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/effect-pg-boss",
3
- "version": "0.6.1",
3
+ "version": "0.7.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": {
@@ -80,7 +80,7 @@ export const defineQueue = <const Name extends string, const Payload extends Job
80
80
  name: options.name,
81
81
  queueOptions: Object.freeze({ ...options.queue }),
82
82
  schema: options.schema,
83
- workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
83
+ workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
84
84
  };
85
85
  return Object.freeze(definition);
86
86
  };
@@ -106,7 +106,7 @@ export const defineSchedule = <const Name extends string>(options: DefineSchedul
106
106
  schedule: definition,
107
107
  }),
108
108
  scheduleOptions: Object.freeze({ tz: "UTC", ...options.schedule }),
109
- workerOptions: Object.freeze({ batchSize: 1, ...options.worker }),
109
+ workerOptions: Object.freeze({ batchSize: 10, burstWhenBatchFull: true, ...options.worker }),
110
110
  };
111
111
  return Object.freeze(definition);
112
112
  };
@@ -1,7 +1,14 @@
1
1
  import { type Context, Effect, Redacted, Schema } from "effect";
2
2
  import type { Job } from "pg-boss";
3
3
  import type { PgBossClient } from "#client.ts";
4
- import { type JobRegistration, jobContext, type QueueDefinition, type QueueWorker, type ScheduledWorker } from "#definition.ts";
4
+ import {
5
+ type JobRegistration,
6
+ jobContext,
7
+ type QueueDefinition,
8
+ type QueueWorker,
9
+ type ScheduleDefinition,
10
+ type ScheduledWorker,
11
+ } from "#definition.ts";
5
12
  import { PgBossPayloadError, PgBossQueueOptionsError, toPgBossError } from "#error.ts";
6
13
  import { ensureQueue } from "#internal/ensureQueue.ts";
7
14
  import { payloadOf, traceJob } from "#internal/tracing.ts";
@@ -18,18 +25,34 @@ function isQueueDefinition(registration: JobRegistration): registration is Queue
18
25
  return registration._tag === "QueueDefinition";
19
26
  }
20
27
 
21
- export const registrationName = (registration: JobRegistration): string => {
28
+ function registrationDefinition(registration: JobRegistration): QueueDefinition | ScheduleDefinition {
22
29
  if (isQueueDefinition(registration)) {
23
- return registration.name;
30
+ return registration;
24
31
  }
25
32
  if (isQueueWorker(registration)) {
26
- return registration.queue.name;
33
+ return registration.queue;
27
34
  }
28
35
  if (isScheduledWorker(registration)) {
29
- return registration.schedule.name;
36
+ return registration.schedule;
30
37
  }
31
38
  throw new TypeError(`Unknown pg-boss registration: ${registration._tag}`);
32
- };
39
+ }
40
+
41
+ export function registrationName(registration: JobRegistration): string {
42
+ return registrationDefinition(registration).name;
43
+ }
44
+
45
+ async function prepareQueues(client: PgBossClient, registrations: readonly JobRegistration[], replaceWorkers: boolean): Promise<void> {
46
+ for (const registration of registrations) {
47
+ if (replaceWorkers && !isQueueDefinition(registration)) {
48
+ await client.offWork(registrationName(registration));
49
+ }
50
+ }
51
+ for (const registration of registrations) {
52
+ const definition = registrationDefinition(registration);
53
+ await ensureQueue(client, definition.name, definition.queueOptions);
54
+ }
55
+ }
33
56
 
34
57
  // The layer requires RegistrationRequirements of its jobs, so its context provides every registered worker.
35
58
  function workerContext<R>(context: Context.Context<R>): Context.Context<unknown>;
@@ -56,18 +79,9 @@ function runQueueWorker(worker: QueueWorker, job: Job<unknown>, context: Context
56
79
  );
57
80
  }
58
81
 
59
- async function registerQueue(
60
- client: PgBossClient,
61
- registration: QueueWorker | QueueDefinition,
62
- context: Context.Context<unknown>,
63
- replaceWorker: boolean,
64
- ): Promise<void> {
82
+ async function registerQueue(client: PgBossClient, registration: QueueWorker | QueueDefinition, context: Context.Context<unknown>): Promise<void> {
65
83
  const queue = registration._tag === "QueueWorker" ? registration.queue : registration;
66
84
  const name = queue.name;
67
- if (replaceWorker && registration._tag === "QueueWorker") {
68
- await client.offWork(name);
69
- }
70
- await ensureQueue(client, name, queue.queueOptions);
71
85
  if (registration._tag === "QueueDefinition") {
72
86
  return;
73
87
  }
@@ -78,17 +92,8 @@ async function registerQueue(
78
92
  });
79
93
  }
80
94
 
81
- async function registerSchedule(
82
- client: PgBossClient,
83
- worker: ScheduledWorker,
84
- context: Context.Context<unknown>,
85
- replaceWorker: boolean,
86
- ): Promise<void> {
95
+ async function registerSchedule(client: PgBossClient, worker: ScheduledWorker, context: Context.Context<unknown>): Promise<void> {
87
96
  const { schedule } = worker;
88
- if (replaceWorker) {
89
- await client.offWork(schedule.name);
90
- }
91
- await ensureQueue(client, schedule.name, schedule.queueOptions);
92
97
  await client.work(schedule.name, schedule.workerOptions, async (jobs: readonly Job<unknown>[]) => {
93
98
  for (const job of jobs) {
94
99
  await Effect.runPromise(Effect.provide(traceJob(worker.effect, job, schedule.name), context), {
@@ -117,12 +122,13 @@ export const registerJobs = <R>(
117
122
  catch: (error) => (error instanceof PgBossQueueOptionsError ? error : toPgBossError("register", error)),
118
123
  try: async () => {
119
124
  registrationNames(registrations);
125
+ await prepareQueues(client, registrations, replaceWorkers);
120
126
  const provided = workerContext(context);
121
127
  for (const registration of registrations) {
122
128
  if (isQueueWorker(registration) || isQueueDefinition(registration)) {
123
- await registerQueue(client, registration, provided, replaceWorkers);
129
+ await registerQueue(client, registration, provided);
124
130
  } else if (isScheduledWorker(registration)) {
125
- await registerSchedule(client, registration, provided, replaceWorkers);
131
+ await registerSchedule(client, registration, provided);
126
132
  }
127
133
  }
128
134
  },
@@ -35,7 +35,11 @@ export type PgBossLayerOptions<TRegistrations extends readonly JobRegistration[]
35
35
  export interface PgBossDefinition<TIdentifier extends string = string> extends Context.Service<TIdentifier, PgBossService> {
36
36
  readonly layer: <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(
37
37
  options: PgBossLayerOptions<TRegistrations, TErrorRequirements>,
38
- ) => Layer.Layer<TIdentifier, PgBossError | PgBossQueueOptionsError, RegistrationRequirements<TRegistrations> | TErrorRequirements>;
38
+ ) => Layer.Layer<
39
+ TIdentifier,
40
+ PgBossError | PgBossQueueOptionsError,
41
+ Exclude<RegistrationRequirements<TRegistrations>, TIdentifier> | TErrorRequirements
42
+ >;
39
43
  }
40
44
 
41
45
  function logClientError(error: Error): Effect.Effect<void> {
@@ -47,27 +51,33 @@ export const makePgBoss = <const TIdentifier extends string>(identifier: TIdenti
47
51
 
48
52
  const layer = <const TRegistrations extends readonly JobRegistration[], TErrorRequirements = never>(
49
53
  options: PgBossLayerOptions<TRegistrations, TErrorRequirements>,
50
- ): Layer.Layer<TIdentifier, PgBossError | PgBossQueueOptionsError, RegistrationRequirements<TRegistrations> | TErrorRequirements> => {
51
- type Requirements = RegistrationRequirements<TRegistrations> | TErrorRequirements;
54
+ ): Layer.Layer<
55
+ TIdentifier,
56
+ PgBossError | PgBossQueueOptionsError,
57
+ Exclude<RegistrationRequirements<TRegistrations>, TIdentifier> | TErrorRequirements
58
+ > => {
59
+ type Requirements = Exclude<RegistrationRequirements<TRegistrations>, TIdentifier> | TErrorRequirements;
52
60
  const names = options.jobs.map(registrationName);
53
61
  const { clientFactory, clientCacheKey, jobs, onError, stop, ...constructorOptions } = options;
54
62
 
55
63
  const acquire = Effect.acquireRelease(
56
64
  Effect.gen(function* () {
57
- const context = yield* Effect.context<Requirements>();
65
+ const dependencies = yield* Effect.context<Requirements>();
58
66
  const acquired = yield* acquireClient({
59
67
  clientCacheKey,
60
68
  clientFactory,
61
69
  constructor: constructorOptions,
62
70
  });
63
- const reportError: (error: Error) => Effect.Effect<unknown, never, Requirements> = onError ?? logClientError;
71
+ const service = makeService(acquired.client, names, constructorOptions.schema);
72
+ const context = Context.add(dependencies, Service, service);
73
+ const reportError: (error: Error) => Effect.Effect<unknown, never, Requirements | TIdentifier> = onError ?? logClientError;
64
74
  const errorListener = (error: Error) => {
65
75
  void Effect.runPromise(Effect.exit(Effect.provide(reportError(error), context)));
66
76
  };
67
77
  acquired.client.on("error", errorListener);
68
78
  const registration = registerJobs(acquired.client, jobs, context, acquired.reused);
69
79
  return yield* registration.pipe(
70
- Effect.as({ acquired, context, errorListener }),
80
+ Effect.as({ acquired, errorListener, service }),
71
81
  Effect.onError(() => {
72
82
  acquired.client.off("error", errorListener);
73
83
  return releaseClient(acquired, stop);
@@ -82,7 +92,7 @@ export const makePgBoss = <const TIdentifier extends string>(identifier: TIdenti
82
92
 
83
93
  return Layer.effect(
84
94
  Service,
85
- Effect.map(acquire, ({ acquired }) => makeService(acquired.client, names, constructorOptions.schema)),
95
+ Effect.map(acquire, ({ service }) => service),
86
96
  );
87
97
  };
88
98