@teamscala/service-boot 0.23.307 → 0.23.309

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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "name": "@teamscala/service-boot",
8
8
  "type": "module",
9
- "version": "0.23.307",
9
+ "version": "0.23.309",
10
10
  "sideEffects": false,
11
11
  "files": [
12
12
  "src"
@@ -18,7 +18,7 @@ export type PgBossJobHandler = (ctx: {
18
18
  config: ScheduledJobConfig;
19
19
  /** Per-job data payload from a one-shot `boss.send()` — absent for scheduled jobs. */
20
20
  jobData?: unknown;
21
- }) => Promise<void> | void;
21
+ }) => Promise<unknown> | unknown;
22
22
  export declare const pgBossHandlerRegistry: import("@teamscala/generic-registry/create-registry").Registry<PgBossJobHandler>;
23
23
  /**
24
24
  * Register a handler for a `scheduled_job.handler_slug`. Idempotent on re-import
@@ -20,7 +20,7 @@ export type PgBossJobHandler = (ctx: {
20
20
  config: ScheduledJobConfig;
21
21
  /** Per-job data payload from a one-shot `boss.send()` — absent for scheduled jobs. */
22
22
  jobData?: unknown;
23
- }) => Promise<void> | void;
23
+ }) => Promise<unknown> | unknown;
24
24
 
25
25
  export const pgBossHandlerRegistry = createRegistry<PgBossJobHandler>(
26
26
  "pg-boss-handlers",
@@ -101,7 +101,7 @@ async function resolveHandler(
101
101
  handlerSlug: string,
102
102
  config: ScheduledJobConfig,
103
103
  jobData?: unknown,
104
- ): Promise<void> {
104
+ ): Promise<unknown> {
105
105
  const handler = pgBossHandlerRegistry.get(handlerSlug);
106
106
  if (!handler) {
107
107
  throw new Error(
@@ -109,7 +109,7 @@ async function resolveHandler(
109
109
  `register it via pgBossHandlerRegistry.register(slug, fn) before the job fires`,
110
110
  );
111
111
  }
112
- await handler({ config, jobData });
112
+ return await handler({ config, jobData });
113
113
  }
114
114
 
115
115
  export async function mountPgBoss(
@@ -204,8 +204,15 @@ export async function mountPgBoss(
204
204
  // underlying SQL is ON CONFLICT DO NOTHING, so calling it on every
205
205
  // boot is a safe idempotent assert, never a duplicate-creation error.
206
206
  await boss.createQueue(queueName);
207
- await boss.work(queueName, async (job) => {
208
- await resolveHandler(config.handler_slug, config, job?.data);
207
+ await boss.work(queueName, async (jobs) => {
208
+ let result: unknown;
209
+ for (const job of jobs) {
210
+ result = await resolveHandler(config.handler_slug, config, job.data);
211
+ }
212
+ // pg-boss stores the work handler return as job output when
213
+ // exactly one job was processed (manager.js complete()). For
214
+ // batch/scheduled jobs the return is not stored.
215
+ return jobs.length === 1 ? result : undefined;
209
216
  });
210
217
 
211
218
  if (config.cron) {