bunderstack 0.23.0 → 0.23.3

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
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to `bunderstack` will be documented in this file.
4
4
 
5
+ ## [0.23.2] - 2026-08-31
6
+
7
+ ### Fixed
8
+
9
+ - **Renewable job leases.** Active handlers renew their fenced lease while
10
+ running, preventing a healthy long-running job from being reclaimed.
11
+ - **Bounded execution.** Jobs may use `leaseDuration`, `maxRuntime`, and
12
+ `ctx.signal`; `timeout` remains a deprecated alias for the lease duration.
13
+ - **Safe observability.** Queue lifecycle events are structured JSON without
14
+ payloads or exception stacks; agent-chat forwards queue cancellation to its
15
+ provider request.
16
+
17
+ ## [0.23.1] - 2026-08-31
18
+
19
+ ### Changed
20
+
21
+ - **Continuous background-job concurrency.** Workers now fill declared
22
+ concurrency above the internal ten-row claim batch and refill each freed slot
23
+ immediately instead of waiting for the slowest job in a wave. Deterministic
24
+ fixture ticks retain complete-wave execution.
25
+
5
26
  ## [0.23.0] - 2026-08-29
6
27
 
7
28
  ### Added
@@ -4,7 +4,18 @@ import type { EmailFacade } from '../email.js';
4
4
  import type { StorageFacade } from '../runtime.js';
5
5
  import { type CatchUp } from './slots.js';
6
6
  export declare const DEFAULT_RETRIES = 3;
7
+ export declare const DEFAULT_LEASE_DURATION_MS = 60000;
8
+ /** @deprecated Use DEFAULT_LEASE_DURATION_MS. */
7
9
  export declare const DEFAULT_TIMEOUT_MS = 60000;
10
+ export type BackgroundTiming = {
11
+ /** Lease duration in ms; an expired lease sends the job back to pending. */
12
+ leaseDuration?: number;
13
+ /** Optional cooperative execution deadline in ms. */
14
+ maxRuntime?: number;
15
+ /** @deprecated Use leaseDuration. */
16
+ timeout?: number;
17
+ };
18
+ export declare function leaseDurationFor<T extends BackgroundTiming>(def: T): number;
8
19
  export type EnqueueOptions = {
9
20
  /** Collapse duplicate enqueues while the queue row is non-terminal. */
10
21
  dedupeKey?: string;
@@ -40,9 +51,11 @@ export type JobContext<TSchema extends Record<string, unknown> = Record<string,
40
51
  storage: StorageFacade;
41
52
  jobs: JobsRuntimeFacade;
42
53
  realtime: RealtimeFacade<TSchema>;
54
+ /** Aborted when execution reaches its deadline or the job loses its lease. */
55
+ signal: AbortSignal;
43
56
  };
44
57
  export type BunderstackJobContext<TSchema extends Record<string, unknown> = Record<string, unknown>, TEnvResult = Record<string, unknown>> = JobContext<TSchema, TEnvResult>;
45
- export type QueueJobDefinition<TInput, TSchema extends Record<string, unknown> = Record<string, unknown>, TEnvResult = Record<string, unknown>> = {
58
+ export type QueueJobDefinition<TInput, TSchema extends Record<string, unknown> = Record<string, unknown>, TEnvResult = Record<string, unknown>> = BackgroundTiming & {
46
59
  kind: 'job';
47
60
  /** Standard Schema payload; parsed at enqueue AND before the handler runs. */
48
61
  input?: StandardSchemaV1<unknown, TInput>;
@@ -55,8 +68,6 @@ export type QueueJobDefinition<TInput, TSchema extends Record<string, unknown> =
55
68
  };
56
69
  /** Max simultaneous `running` rows of this type, enforced per worker. */
57
70
  concurrency?: number;
58
- /** Lease duration in ms; an expired lease sends the job back to pending. */
59
- timeout?: number;
60
71
  handler: (input: TInput, ctx: JobContext<TSchema, TEnvResult>) => Promise<void> | void;
61
72
  /** Fires once, after the final attempt fails. Errors here are logged, never retried. */
62
73
  onFailed?: (input: TInput, error: Error, ctx: JobContext<TSchema, TEnvResult>) => Promise<void> | void;
@@ -64,7 +75,7 @@ export type QueueJobDefinition<TInput, TSchema extends Record<string, unknown> =
64
75
  export type CronInvocation = {
65
76
  scheduledFor: Date;
66
77
  };
67
- export type CronDefinition<TSchema extends Record<string, unknown> = Record<string, unknown>, TEnvResult = Record<string, unknown>, TSchedule extends string = string> = {
78
+ export type CronDefinition<TSchema extends Record<string, unknown> = Record<string, unknown>, TEnvResult = Record<string, unknown>, TSchedule extends string = string> = BackgroundTiming & {
68
79
  kind: 'cron';
69
80
  schedule: TSchedule;
70
81
  /** Attempts after the first failure. Default 3 (so 4 total attempts). */
@@ -74,8 +85,6 @@ export type CronDefinition<TSchema extends Record<string, unknown> = Record<stri
74
85
  baseMs?: number;
75
86
  factor?: number;
76
87
  };
77
- /** Lease duration in ms; an expired lease sends the slot back to pending. */
78
- timeout?: number;
79
88
  /** How missed slots are handled on wake. Default 'latest'. */
80
89
  catchUp?: CatchUp;
81
90
  /** How far back catch-up looks, in ms. Default 1 hour. */
@@ -1 +1 @@
1
- {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/jobs/define.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C,OAAO,EAAe,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAEnD,eAAO,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,kBAAkB,QAAS,CAAA;AAExC,MAAM,MAAM,cAAc,GAAG;IAC3B,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAA;IACX,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,OAAO,EACf,IAAI,C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C,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,CAAC,GACvD,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC3B,CAAA"}
@@ -1,7 +1,12 @@
1
1
  import { parseCron } from './cron.js';
2
2
  import { CRON_PREFIX } from './slots.js';
3
3
  export const DEFAULT_RETRIES = 3;
4
- export const DEFAULT_TIMEOUT_MS = 60_000;
4
+ export const DEFAULT_LEASE_DURATION_MS = 60_000;
5
+ /** @deprecated Use DEFAULT_LEASE_DURATION_MS. */
6
+ export const DEFAULT_TIMEOUT_MS = DEFAULT_LEASE_DURATION_MS;
7
+ export function leaseDurationFor(def) {
8
+ return def.leaseDuration ?? def.timeout ?? DEFAULT_LEASE_DURATION_MS;
9
+ }
5
10
  /** Throws when a definition is unusable. Safe to call more than once. */
6
11
  export function validateBackgroundDefs(defs) {
7
12
  for (const [name, def] of Object.entries(defs)) {
@@ -15,8 +20,15 @@ export function validateBackgroundDefs(defs) {
15
20
  (def.retries < 0 || !Number.isInteger(def.retries))) {
16
21
  throw new Error(`[bunderstack] background task "${name}": retries must be a non-negative integer`);
17
22
  }
18
- if (def.timeout !== undefined && def.timeout <= 0) {
19
- throw new Error(`[bunderstack] background task "${name}": timeout must be positive`);
23
+ if (def.timeout !== undefined && def.leaseDuration !== undefined) {
24
+ throw new Error(`[bunderstack] background task "${name}": timeout and leaseDuration cannot both be declared`);
25
+ }
26
+ for (const field of ['timeout', 'leaseDuration', 'maxRuntime']) {
27
+ const value = def[field];
28
+ if (value !== undefined &&
29
+ (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0)) {
30
+ throw new Error(`[bunderstack] background task "${name}": ${field} must be a positive finite integer`);
31
+ }
20
32
  }
21
33
  if (def.kind === 'cron') {
22
34
  parseCron(def.schedule);
@@ -1 +1 @@
1
- {"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/jobs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E;YAElE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,EAAE,CAAA;QAChC,CAAC;QACD,IAAI,CACF,GAAiE;YAEjE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,CAAA;QACjC,CAAC;QACD,6DAA6D;QAC7D,MAAM,CAA+B,IAAW;YAC9C,sBAAsB,CAAC,IAAI,CAAC,CAAA;YAC5B,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["// src/jobs/define.ts — job definition types and the typed builder.\n// `createJobsBuilder` exists purely to carry\n// TSchema/TEnvResult typing into inline callbacks and extracted files.\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport type { DbFor } from '../db'\nimport type { EmailFacade } from '../email'\nimport type { StorageFacade } from '../runtime'\n\nimport { parseCron } from './cron'\nimport { CRON_PREFIX, type CatchUp } from './slots'\n\nexport const DEFAULT_RETRIES = 3\nexport const DEFAULT_TIMEOUT_MS = 60_000\n\nexport type EnqueueOptions = {\n /** Collapse duplicate enqueues while the queue row is non-terminal. */\n dedupeKey?: string\n /** Milliseconds from now until the job becomes claimable. */\n delay?: number\n /** Absolute time the job becomes claimable; wins over `delay`. */\n runAt?: Date | number\n}\n\nexport type TickResult = {\n /** Rows moved from pending to running this tick. */\n claimed: number\n /** Handlers that completed successfully. */\n ran: number\n /** Handlers that threw, whether or not they will be retried. */\n failed: number\n}\n\n/**\n * The untyped runtime facade. Job handlers and API context expose this shape;\n * `app.jobs` narrows `enqueue` to the declared job names/payloads.\n */\nexport type JobsRuntimeFacade = {\n enqueue(\n name: string,\n input?: unknown,\n opts?: EnqueueOptions,\n ): Promise<{ id: string }>\n /** Run one poll cycle deterministically (tests). `now` defaults to Date.now(). */\n tick(now?: number): Promise<TickResult>\n}\n\nimport type { RealtimeFacade } from '../realtime/facade'\n\nexport type JobContext<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = {\n db: DbFor<TSchema>\n env: TEnvResult\n email: EmailFacade\n storage: StorageFacade\n jobs: JobsRuntimeFacade\n realtime: RealtimeFacade<TSchema>\n}\n\nexport type BunderstackJobContext<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = JobContext<TSchema, TEnvResult>\n\nexport type QueueJobDefinition<\n TInput,\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = {\n kind: 'job'\n /** Standard Schema payload; parsed at enqueue AND before the handler runs. */\n input?: StandardSchemaV1<unknown, TInput>\n /** Attempts after the first failure. Default 3 (so 4 total attempts). */\n retries?: number\n /** Delay before retry N (1-based). Default exponential: 1s, 2s, 4s, … */\n backoff?: ((attempt: number) => number) | { baseMs?: number; factor?: number }\n /** Max simultaneous `running` rows of this type, enforced per worker. */\n concurrency?: number\n /** Lease duration in ms; an expired lease sends the job back to pending. */\n timeout?: number\n handler: (\n input: TInput,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n /** Fires once, after the final attempt fails. Errors here are logged, never retried. */\n onFailed?: (\n input: TInput,\n error: Error,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n}\n\nexport type CronInvocation = { scheduledFor: Date }\n\nexport type CronDefinition<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n TSchedule extends string = string,\n> = {\n kind: 'cron'\n schedule: TSchedule\n /** Attempts after the first failure. Default 3 (so 4 total attempts). */\n retries?: number\n /** Delay before retry N (1-based). Default exponential: 1s, 2s, 4s, … */\n backoff?: ((attempt: number) => number) | { baseMs?: number; factor?: number }\n /** Lease duration in ms; an expired lease sends the slot back to pending. */\n timeout?: number\n /** How missed slots are handled on wake. Default 'latest'. */\n catchUp?: CatchUp\n /** How far back catch-up looks, in ms. Default 1 hour. */\n catchUpWindow?: number\n handler: (\n invocation: CronInvocation,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n /** Fires once, after the final attempt fails. Errors here are logged, never retried. */\n onFailed?: (\n invocation: CronInvocation,\n error: Error,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n}\n\nexport type BackgroundDefinition =\n | QueueJobDefinition<any, any, any>\n | CronDefinition<any, any>\nexport type BackgroundDefs = Record<string, BackgroundDefinition>\n\n/** @deprecated Use QueueJobDefinition. */\nexport type JobDefinition<\n TInput,\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = QueueJobDefinition<TInput, TSchema, TEnvResult>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyJobDefinition = QueueJobDefinition<any, any, any>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyBackgroundDefinition =\n | QueueJobDefinition<any, any, any>\n | CronDefinition<any, any, any>\nexport type JobsDefs = BackgroundDefs\n\nexport type QueueJobKeys<TDefs extends BackgroundDefs> = {\n [K in keyof TDefs & string]: TDefs[K] extends QueueJobDefinition<\n any,\n any,\n any\n >\n ? K\n : never\n}[keyof TDefs & string]\n\n/** Throws when a definition is unusable. Safe to call more than once. */\nexport function validateBackgroundDefs(defs: BackgroundDefs): void {\n for (const [name, def] of Object.entries(defs)) {\n if (typeof def.handler !== 'function') {\n throw new Error(`[bunderstack] background task \"${name}\" has no handler`)\n }\n if (def.kind === 'job' && name.startsWith(CRON_PREFIX)) {\n throw new Error(\n `[bunderstack] job \"${name}\": the \"${CRON_PREFIX}\" prefix is reserved for cron tasks`,\n )\n }\n if (\n def.retries !== undefined &&\n (def.retries < 0 || !Number.isInteger(def.retries))\n ) {\n throw new Error(\n `[bunderstack] background task \"${name}\": retries must be a non-negative integer`,\n )\n }\n if (def.timeout !== undefined && def.timeout <= 0) {\n throw new Error(\n `[bunderstack] background task \"${name}\": timeout must be positive`,\n )\n }\n if (def.kind === 'cron') {\n parseCron(def.schedule)\n if ((def as { concurrency?: number }).concurrency !== undefined) {\n throw new Error(\n `[bunderstack] cron \"${name}\": concurrency is not supported for cron tasks — slots are already unique`,\n )\n }\n if (def.catchUpWindow !== undefined && def.catchUpWindow <= 0) {\n throw new Error(\n `[bunderstack] cron \"${name}\": catchUpWindow must be positive`,\n )\n }\n continue\n }\n if (\n def.concurrency !== undefined &&\n (def.concurrency < 1 || !Number.isInteger(def.concurrency))\n ) {\n throw new Error(\n `[bunderstack] job \"${name}\": concurrency must be a positive integer`,\n )\n }\n }\n}\n\n/** @deprecated Use validateBackgroundDefs. */\nexport const validateJobsDefs = validateBackgroundDefs\n\n/**\n * Delay in ms before retry `attempt` (1-based = the attempt that just failed).\n * Jittered by ±20% so a shared outage does not retry every job in lockstep.\n * A caller-supplied backoff function is returned verbatim — the caller owns it.\n */\nexport function backoffMs(\n def: AnyBackgroundDefinition,\n attempt: number,\n): number {\n const b = def.backoff\n if (typeof b === 'function') return b(attempt)\n const baseMs = b?.baseMs ?? 1000\n const factor = b?.factor ?? 2\n const flat = baseMs * factor ** (attempt - 1)\n return Math.round(flat * (0.8 + Math.random() * 0.4))\n}\n\n/**\n * Build the `j` instance bunderstack hands to the config's `jobs` builder\n * callback (and exports for multi-file job setups).\n */\nexport function createJobsBuilder<\n TSchema extends Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n>() {\n return {\n /** Identity with inference: pins TInput from the schema output. */\n job<TInput = undefined>(\n def: Omit<QueueJobDefinition<TInput, TSchema, TEnvResult>, 'kind'>,\n ): QueueJobDefinition<TInput, TSchema, TEnvResult> {\n return { kind: 'job', ...def }\n },\n cron<const TSchedule extends string>(\n def: Omit<CronDefinition<TSchema, TEnvResult, TSchedule>, 'kind'>,\n ): CronDefinition<TSchema, TEnvResult, TSchedule> {\n parseCron(def.schedule)\n return { kind: 'cron', ...def }\n },\n /** Identity with validation: returns the defs map, typed. */\n define<TDefs extends BackgroundDefs>(defs: TDefs): TDefs {\n validateBackgroundDefs(defs)\n return defs\n },\n }\n}\n\n/** Type of the `j` instance — for builder callbacks declared in separate files. */\nexport type BunderstackJobsBuilder<\n TSchema extends Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = ReturnType<typeof createJobsBuilder<TSchema, TEnvResult>>\n\n// Infers TInput from the JobDefinition's own type argument rather than\n// pattern-matching the (optional, so union-with-undefined) `input` property —\n// A required-property pattern fails structurally because `input` is optional,\n// so infer from the definition's own type argument instead.\ntype JobInputOf<TDef> =\n TDef extends QueueJobDefinition<infer TInput, any, any> ? TInput : undefined\n\n/**\n * `app.jobs`: `enqueue` narrowed to declared names + payloads. `Omit`s the\n * runtime facade's loose `enqueue` first — intersecting two same-named\n * methods instead would make TS treat them as overloaded, so the loose\n * `(name: string, ...)` signature would still accept any name.\n */\nexport type JobsFacade<TDefs extends JobsDefs> = Omit<\n JobsRuntimeFacade,\n 'enqueue'\n> & {\n enqueue<K extends QueueJobKeys<TDefs>>(\n name: K,\n ...rest: JobInputOf<TDefs[K]> extends undefined\n ? [input?: undefined, opts?: EnqueueOptions]\n : [input: JobInputOf<TDefs[K]>, opts?: EnqueueOptions]\n ): Promise<{ id: string }>\n}\n"]}
1
+ {"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/jobs/define.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAE,WAAW,EAAgB,MAAM,SAAS,CAAA;AAEnD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAA;AAChC,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAC/C,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAW3D,MAAM,UAAU,gBAAgB,CAA6B,GAAM;IACjE,OAAO,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,OAAO,IAAI,yBAAyB,CAAA;AACtE,CAAC;AA4ID,yEAAyE;AACzE,MAAM,UA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G,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAA;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAI/B,OAAO;QACL,mEAAmE;QACnE,GAAG,CACD,GAAkE;YAElE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,EAAE,CAAA;QAChC,CAAC;QACD,IAAI,CACF,GAAiE;YAEjE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,CAAA;QACjC,CAAC;QACD,6DAA6D;QAC7D,MAAM,CAA+B,IAAW;YAC9C,sBAAsB,CAAC,IAAI,CAAC,CAAA;YAC5B,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["// src/jobs/define.ts — job definition types and the typed builder.\n// `createJobsBuilder` exists purely to carry\n// TSchema/TEnvResult typing into inline callbacks and extracted files.\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\n\nimport type { DbFor } from '../db'\nimport type { EmailFacade } from '../email'\nimport type { StorageFacade } from '../runtime'\n\nimport { parseCron } from './cron'\nimport { CRON_PREFIX, type CatchUp } from './slots'\n\nexport const DEFAULT_RETRIES = 3\nexport const DEFAULT_LEASE_DURATION_MS = 60_000\n/** @deprecated Use DEFAULT_LEASE_DURATION_MS. */\nexport const DEFAULT_TIMEOUT_MS = DEFAULT_LEASE_DURATION_MS\n\nexport type BackgroundTiming = {\n /** Lease duration in ms; an expired lease sends the job back to pending. */\n leaseDuration?: number\n /** Optional cooperative execution deadline in ms. */\n maxRuntime?: number\n /** @deprecated Use leaseDuration. */\n timeout?: number\n}\n\nexport function leaseDurationFor<T extends BackgroundTiming>(def: T): number {\n return def.leaseDuration ?? def.timeout ?? DEFAULT_LEASE_DURATION_MS\n}\n\nexport type EnqueueOptions = {\n /** Collapse duplicate enqueues while the queue row is non-terminal. */\n dedupeKey?: string\n /** Milliseconds from now until the job becomes claimable. */\n delay?: number\n /** Absolute time the job becomes claimable; wins over `delay`. */\n runAt?: Date | number\n}\n\nexport type TickResult = {\n /** Rows moved from pending to running this tick. */\n claimed: number\n /** Handlers that completed successfully. */\n ran: number\n /** Handlers that threw, whether or not they will be retried. */\n failed: number\n}\n\n/**\n * The untyped runtime facade. Job handlers and API context expose this shape;\n * `app.jobs` narrows `enqueue` to the declared job names/payloads.\n */\nexport type JobsRuntimeFacade = {\n enqueue(\n name: string,\n input?: unknown,\n opts?: EnqueueOptions,\n ): Promise<{ id: string }>\n /** Run one poll cycle deterministically (tests). `now` defaults to Date.now(). */\n tick(now?: number): Promise<TickResult>\n}\n\nimport type { RealtimeFacade } from '../realtime/facade'\n\nexport type JobContext<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = {\n db: DbFor<TSchema>\n env: TEnvResult\n email: EmailFacade\n storage: StorageFacade\n jobs: JobsRuntimeFacade\n realtime: RealtimeFacade<TSchema>\n /** Aborted when execution reaches its deadline or the job loses its lease. */\n signal: AbortSignal\n}\n\nexport type BunderstackJobContext<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = JobContext<TSchema, TEnvResult>\n\nexport type QueueJobDefinition<\n TInput,\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = BackgroundTiming & {\n kind: 'job'\n /** Standard Schema payload; parsed at enqueue AND before the handler runs. */\n input?: StandardSchemaV1<unknown, TInput>\n /** Attempts after the first failure. Default 3 (so 4 total attempts). */\n retries?: number\n /** Delay before retry N (1-based). Default exponential: 1s, 2s, 4s, … */\n backoff?: ((attempt: number) => number) | { baseMs?: number; factor?: number }\n /** Max simultaneous `running` rows of this type, enforced per worker. */\n concurrency?: number\n handler: (\n input: TInput,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n /** Fires once, after the final attempt fails. Errors here are logged, never retried. */\n onFailed?: (\n input: TInput,\n error: Error,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n}\n\nexport type CronInvocation = { scheduledFor: Date }\n\nexport type CronDefinition<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n TSchedule extends string = string,\n> = BackgroundTiming & {\n kind: 'cron'\n schedule: TSchedule\n /** Attempts after the first failure. Default 3 (so 4 total attempts). */\n retries?: number\n /** Delay before retry N (1-based). Default exponential: 1s, 2s, 4s, … */\n backoff?: ((attempt: number) => number) | { baseMs?: number; factor?: number }\n /** How missed slots are handled on wake. Default 'latest'. */\n catchUp?: CatchUp\n /** How far back catch-up looks, in ms. Default 1 hour. */\n catchUpWindow?: number\n handler: (\n invocation: CronInvocation,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n /** Fires once, after the final attempt fails. Errors here are logged, never retried. */\n onFailed?: (\n invocation: CronInvocation,\n error: Error,\n ctx: JobContext<TSchema, TEnvResult>,\n ) => Promise<void> | void\n}\n\nexport type BackgroundDefinition =\n | QueueJobDefinition<any, any, any>\n | CronDefinition<any, any>\nexport type BackgroundDefs = Record<string, BackgroundDefinition>\n\n/** @deprecated Use QueueJobDefinition. */\nexport type JobDefinition<\n TInput,\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = QueueJobDefinition<TInput, TSchema, TEnvResult>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyJobDefinition = QueueJobDefinition<any, any, any>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyBackgroundDefinition =\n | QueueJobDefinition<any, any, any>\n | CronDefinition<any, any, any>\nexport type JobsDefs = BackgroundDefs\n\nexport type QueueJobKeys<TDefs extends BackgroundDefs> = {\n [K in keyof TDefs & string]: TDefs[K] extends QueueJobDefinition<\n any,\n any,\n any\n >\n ? K\n : never\n}[keyof TDefs & string]\n\n/** Throws when a definition is unusable. Safe to call more than once. */\nexport function validateBackgroundDefs(defs: BackgroundDefs): void {\n for (const [name, def] of Object.entries(defs)) {\n if (typeof def.handler !== 'function') {\n throw new Error(`[bunderstack] background task \"${name}\" has no handler`)\n }\n if (def.kind === 'job' && name.startsWith(CRON_PREFIX)) {\n throw new Error(\n `[bunderstack] job \"${name}\": the \"${CRON_PREFIX}\" prefix is reserved for cron tasks`,\n )\n }\n if (\n def.retries !== undefined &&\n (def.retries < 0 || !Number.isInteger(def.retries))\n ) {\n throw new Error(\n `[bunderstack] background task \"${name}\": retries must be a non-negative integer`,\n )\n }\n if (def.timeout !== undefined && def.leaseDuration !== undefined) {\n throw new Error(\n `[bunderstack] background task \"${name}\": timeout and leaseDuration cannot both be declared`,\n )\n }\n for (const field of ['timeout', 'leaseDuration', 'maxRuntime'] as const) {\n const value = def[field]\n if (\n value !== undefined &&\n (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0)\n ) {\n throw new Error(\n `[bunderstack] background task \"${name}\": ${field} must be a positive finite integer`,\n )\n }\n }\n if (def.kind === 'cron') {\n parseCron(def.schedule)\n if ((def as { concurrency?: number }).concurrency !== undefined) {\n throw new Error(\n `[bunderstack] cron \"${name}\": concurrency is not supported for cron tasks — slots are already unique`,\n )\n }\n if (def.catchUpWindow !== undefined && def.catchUpWindow <= 0) {\n throw new Error(\n `[bunderstack] cron \"${name}\": catchUpWindow must be positive`,\n )\n }\n continue\n }\n if (\n def.concurrency !== undefined &&\n (def.concurrency < 1 || !Number.isInteger(def.concurrency))\n ) {\n throw new Error(\n `[bunderstack] job \"${name}\": concurrency must be a positive integer`,\n )\n }\n }\n}\n\n/** @deprecated Use validateBackgroundDefs. */\nexport const validateJobsDefs = validateBackgroundDefs\n\n/**\n * Delay in ms before retry `attempt` (1-based = the attempt that just failed).\n * Jittered by ±20% so a shared outage does not retry every job in lockstep.\n * A caller-supplied backoff function is returned verbatim — the caller owns it.\n */\nexport function backoffMs(\n def: AnyBackgroundDefinition,\n attempt: number,\n): number {\n const b = def.backoff\n if (typeof b === 'function') return b(attempt)\n const baseMs = b?.baseMs ?? 1000\n const factor = b?.factor ?? 2\n const flat = baseMs * factor ** (attempt - 1)\n return Math.round(flat * (0.8 + Math.random() * 0.4))\n}\n\n/**\n * Build the `j` instance bunderstack hands to the config's `jobs` builder\n * callback (and exports for multi-file job setups).\n */\nexport function createJobsBuilder<\n TSchema extends Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n>() {\n return {\n /** Identity with inference: pins TInput from the schema output. */\n job<TInput = undefined>(\n def: Omit<QueueJobDefinition<TInput, TSchema, TEnvResult>, 'kind'>,\n ): QueueJobDefinition<TInput, TSchema, TEnvResult> {\n return { kind: 'job', ...def }\n },\n cron<const TSchedule extends string>(\n def: Omit<CronDefinition<TSchema, TEnvResult, TSchedule>, 'kind'>,\n ): CronDefinition<TSchema, TEnvResult, TSchedule> {\n parseCron(def.schedule)\n return { kind: 'cron', ...def }\n },\n /** Identity with validation: returns the defs map, typed. */\n define<TDefs extends BackgroundDefs>(defs: TDefs): TDefs {\n validateBackgroundDefs(defs)\n return defs\n },\n }\n}\n\n/** Type of the `j` instance — for builder callbacks declared in separate files. */\nexport type BunderstackJobsBuilder<\n TSchema extends Record<string, unknown>,\n TEnvResult = Record<string, unknown>,\n> = ReturnType<typeof createJobsBuilder<TSchema, TEnvResult>>\n\n// Infers TInput from the JobDefinition's own type argument rather than\n// pattern-matching the (optional, so union-with-undefined) `input` property —\n// A required-property pattern fails structurally because `input` is optional,\n// so infer from the definition's own type argument instead.\ntype JobInputOf<TDef> =\n TDef extends QueueJobDefinition<infer TInput, any, any> ? TInput : undefined\n\n/**\n * `app.jobs`: `enqueue` narrowed to declared names + payloads. `Omit`s the\n * runtime facade's loose `enqueue` first — intersecting two same-named\n * methods instead would make TS treat them as overloaded, so the loose\n * `(name: string, ...)` signature would still accept any name.\n */\nexport type JobsFacade<TDefs extends JobsDefs> = Omit<\n JobsRuntimeFacade,\n 'enqueue'\n> & {\n enqueue<K extends QueueJobKeys<TDefs>>(\n name: K,\n ...rest: JobInputOf<TDefs[K]> extends undefined\n ? [input?: undefined, opts?: EnqueueOptions]\n : [input: JobInputOf<TDefs[K]>, opts?: EnqueueOptions]\n ): Promise<{ id: string }>\n}\n"]}
@@ -1,9 +1,9 @@
1
- export { createJobsBuilder, validateBackgroundDefs, validateJobsDefs, DEFAULT_RETRIES, DEFAULT_TIMEOUT_MS, } from './define.js';
2
- export type { AnyJobDefinition, BackgroundDefinition, BackgroundDefs, BunderstackJobContext, BunderstackJobsBuilder, EnqueueOptions, JobContext, JobDefinition, QueueJobDefinition, CronDefinition, CronInvocation, QueueJobKeys, JobsDefs, JobsFacade, JobsRuntimeFacade, } from './define.js';
1
+ export { createJobsBuilder, validateBackgroundDefs, validateJobsDefs, DEFAULT_RETRIES, DEFAULT_LEASE_DURATION_MS, DEFAULT_TIMEOUT_MS, leaseDurationFor, } from './define.js';
2
+ export type { AnyJobDefinition, BackgroundTiming, BackgroundDefinition, BackgroundDefs, BunderstackJobContext, BunderstackJobsBuilder, EnqueueOptions, JobContext, JobDefinition, QueueJobDefinition, CronDefinition, CronInvocation, QueueJobKeys, JobsDefs, JobsFacade, JobsRuntimeFacade, } from './define.js';
3
3
  export { enqueueJob } from './queue.js';
4
4
  export { createJobRunner } from './worker.js';
5
5
  export { startJobWorker } from './runtime.js';
6
- export type { StartWorkerOptions, RunWorkerOptions, WorkerHandle, } from './runtime.js';
6
+ export type { StartWorkerOptions, RunWorkerOptions, WorkerCycleResult, WorkerHandle, } from './runtime.js';
7
7
  export { parseCron, cronMatches } from './cron.js';
8
8
  export { slotsDue, floorSlot, CRON_PREFIX, SLOT_MS } from './slots.js';
9
9
  export type { CatchUp } from './slots.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,iBAAiB,GAClB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACnE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,iBAAiB,GAClB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,YAAY,EACV,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,GACb,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACnE,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
@@ -1,5 +1,5 @@
1
1
  // src/jobs/index.ts — module surface consumed by bunderstack.
2
- export { createJobsBuilder, validateBackgroundDefs, validateJobsDefs, DEFAULT_RETRIES, DEFAULT_TIMEOUT_MS, } from './define.js';
2
+ export { createJobsBuilder, validateBackgroundDefs, validateJobsDefs, DEFAULT_RETRIES, DEFAULT_LEASE_DURATION_MS, DEFAULT_TIMEOUT_MS, leaseDurationFor, } from './define.js';
3
3
  export { enqueueJob } from './queue.js';
4
4
  export { createJobRunner } from './worker.js';
5
5
  export { startJobWorker } from './runtime.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAA;AAkBjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAM1C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA","sourcesContent":["// src/jobs/index.ts — module surface consumed by bunderstack.\nexport {\n createJobsBuilder,\n validateBackgroundDefs,\n validateJobsDefs,\n DEFAULT_RETRIES,\n DEFAULT_TIMEOUT_MS,\n} from './define'\nexport type {\n AnyJobDefinition,\n BackgroundDefinition,\n BackgroundDefs,\n BunderstackJobContext,\n BunderstackJobsBuilder,\n EnqueueOptions,\n JobContext,\n JobDefinition,\n QueueJobDefinition,\n CronDefinition,\n CronInvocation,\n QueueJobKeys,\n JobsDefs,\n JobsFacade,\n JobsRuntimeFacade,\n} from './define'\nexport { enqueueJob } from './queue'\nexport { createJobRunner } from './worker'\nexport { startJobWorker } from './runtime'\nexport type {\n StartWorkerOptions,\n RunWorkerOptions,\n WorkerHandle,\n} from './runtime'\nexport { parseCron, cronMatches } from './cron'\nexport { slotsDue, floorSlot, CRON_PREFIX, SLOT_MS } from './slots'\nexport type { CatchUp } from './slots'\nexport type { TickResult } from './define'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,UAAU,CAAA;AAmBjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAO1C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA","sourcesContent":["// src/jobs/index.ts — module surface consumed by bunderstack.\nexport {\n createJobsBuilder,\n validateBackgroundDefs,\n validateJobsDefs,\n DEFAULT_RETRIES,\n DEFAULT_LEASE_DURATION_MS,\n DEFAULT_TIMEOUT_MS,\n leaseDurationFor,\n} from './define'\nexport type {\n AnyJobDefinition,\n BackgroundTiming,\n BackgroundDefinition,\n BackgroundDefs,\n BunderstackJobContext,\n BunderstackJobsBuilder,\n EnqueueOptions,\n JobContext,\n JobDefinition,\n QueueJobDefinition,\n CronDefinition,\n CronInvocation,\n QueueJobKeys,\n JobsDefs,\n JobsFacade,\n JobsRuntimeFacade,\n} from './define'\nexport { enqueueJob } from './queue'\nexport { createJobRunner } from './worker'\nexport { startJobWorker } from './runtime'\nexport type {\n StartWorkerOptions,\n RunWorkerOptions,\n WorkerCycleResult,\n WorkerHandle,\n} from './runtime'\nexport { parseCron, cronMatches } from './cron'\nexport { slotsDue, floorSlot, CRON_PREFIX, SLOT_MS } from './slots'\nexport type { CatchUp } from './slots'\nexport type { TickResult } from './define'\n"]}
@@ -2,10 +2,14 @@ export type WorkerHandle = {
2
2
  readonly closed: Promise<void>;
3
3
  close(): Promise<void>;
4
4
  };
5
+ export type WorkerCycleResult = {
6
+ wake?: Promise<void>;
7
+ };
5
8
  export type StartWorkerOptions = {
6
9
  signal?: AbortSignal;
7
10
  pollIntervalMs?: number;
8
- tick: (now: number) => Promise<void>;
11
+ tick: (now: number) => Promise<void | WorkerCycleResult>;
12
+ drain?: () => Promise<void>;
9
13
  onError?: (error: Error) => void;
10
14
  };
11
15
  export type RunWorkerOptions = StartWorkerOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/jobs/runtime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AAmBjD,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,YAAY,CA0BxE"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/jobs/runtime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAA;AAExD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,iBAAiB,CAAC,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAA;AA+BjD,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,YAAY,CAiCxE"}
@@ -1,17 +1,25 @@
1
1
  function toError(error) {
2
2
  return error instanceof Error ? error : new Error(String(error));
3
3
  }
4
- function wait(ms, signal) {
4
+ function waitForNext(ms, signal, wake, onError) {
5
5
  return new Promise((resolve) => {
6
- if (signal.aborted)
7
- return resolve();
6
+ let settled = false;
8
7
  const timer = setTimeout(done, ms);
9
8
  function done() {
9
+ if (settled)
10
+ return;
11
+ settled = true;
10
12
  clearTimeout(timer);
11
13
  signal.removeEventListener('abort', done);
12
14
  resolve();
13
15
  }
14
16
  signal.addEventListener('abort', done, { once: true });
17
+ void wake?.then(done, (error) => {
18
+ onError?.(toError(error));
19
+ done();
20
+ });
21
+ if (signal.aborted)
22
+ done();
15
23
  });
16
24
  }
17
25
  export function startJobWorker(options) {
@@ -24,17 +32,19 @@ export function startJobWorker(options) {
24
32
  const closed = (async () => {
25
33
  try {
26
34
  while (!controller.signal.aborted) {
35
+ let cycle = undefined;
27
36
  try {
28
- await options.tick(Date.now());
37
+ cycle = await options.tick(Date.now());
29
38
  }
30
39
  catch (error) {
31
40
  options.onError?.(toError(error));
32
41
  }
33
- await wait(pollIntervalMs, controller.signal);
42
+ await waitForNext(pollIntervalMs, controller.signal, cycle?.wake, options.onError);
34
43
  }
35
44
  }
36
45
  finally {
37
46
  options.signal?.removeEventListener('abort', abort);
47
+ await options.drain?.();
38
48
  }
39
49
  })();
40
50
  const close = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/jobs/runtime.ts"],"names":[],"mappings":"AAcA,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,SAAS,IAAI,CAAC,EAAU,EAAE,MAAmB;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,OAAO,EAAE,CAAA;QACpC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAClC,SAAS,IAAI;YACX,YAAY,CAAC,KAAK,CAAC,CAAA;YAC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AU,CAAC,KAAK,EAAE,CAAA;QAClB,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["export type WorkerHandle = {\n readonly closed: Promise<void>\n close(): Promise<void>\n}\n\nexport type StartWorkerOptions = {\n signal?: AbortSignal\n pollIntervalMs?: number\n tick: (now: number) => Promise<void>\n onError?: (error: Error) => void\n}\n\nexport type RunWorkerOptions = StartWorkerOptions\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error))\n}\n\nfunction wait(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve) => {\n if (signal.aborted) return resolve()\n const timer = setTimeout(done, ms)\n function done() {\n clearTimeout(timer)\n signal.removeEventListener('abort', done)\n resolve()\n }\n signal.addEventListener('abort', done, { once: true })\n })\n}\n\nexport function startJobWorker(options: StartWorkerOptions): WorkerHandle {\n const controller = new AbortController()\n const pollIntervalMs = options.pollIntervalMs ?? 1_000\n const abort = () => controller.abort()\n options.signal?.addEventListener('abort', abort, { once: true })\n if (options.signal?.aborted) abort()\n\n const closed = (async () => {\n try {\n while (!controller.signal.aborted) {\n try {\n await options.tick(Date.now())\n } catch (error) {\n options.onError?.(toError(error))\n }\n await wait(pollIntervalMs, controller.signal)\n }\n } finally {\n options.signal?.removeEventListener('abort', abort)\n }\n })()\n const close = () => {\n controller.abort()\n return closed\n }\n return { closed, close }\n}\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/jobs/runtime.ts"],"names":[],"mappings":"AAiBA,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAClE,CAAC;AAED,SAAS,WAAW,CAClB,EAAU,EACV,MAAmB,EACnB,IAA+B,EAC/B,OAA6C;IAE7C,O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AAO,EAAE,CAAC;gBAClC,IAAI,KAAK,GAA6B,SAAS,CAAA;gBAC/C,IAAI,CAAC;oBACH,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;gBACxC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;gBACnC,CAAC;gBACD,MAAM,WAAW,CACf,cAAc,EACd,UAAU,CAAC,MAAM,EACjB,KAAK,EAAE,IAAI,EACX,OAAO,CAAC,OAAO,CAChB,CAAA;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YACnD,MAAM,OAAO,CAAC,KAAK,EAAE,EAAE,CAAA;QACzB,CAAC;IACH,CAAC,CAAC,EAAE,CAAA;IACJ,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,UAAU,CAAC,KAAK,EAAE,CAAA;QAClB,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["export type WorkerHandle = {\n readonly closed: Promise<void>\n close(): Promise<void>\n}\n\nexport type WorkerCycleResult = { wake?: Promise<void> }\n\nexport type StartWorkerOptions = {\n signal?: AbortSignal\n pollIntervalMs?: number\n tick: (now: number) => Promise<void | WorkerCycleResult>\n drain?: () => Promise<void>\n onError?: (error: Error) => void\n}\n\nexport type RunWorkerOptions = StartWorkerOptions\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error))\n}\n\nfunction waitForNext(\n ms: number,\n signal: AbortSignal,\n wake: Promise<void> | undefined,\n onError: ((error: Error) => void) | undefined,\n): Promise<void> {\n return new Promise((resolve) => {\n let settled = false\n const timer = setTimeout(done, ms)\n function done() {\n if (settled) return\n settled = true\n clearTimeout(timer)\n signal.removeEventListener('abort', done)\n resolve()\n }\n signal.addEventListener('abort', done, { once: true })\n void wake?.then(done, (error) => {\n onError?.(toError(error))\n done()\n })\n if (signal.aborted) done()\n })\n}\n\nexport function startJobWorker(options: StartWorkerOptions): WorkerHandle {\n const controller = new AbortController()\n const pollIntervalMs = options.pollIntervalMs ?? 1_000\n const abort = () => controller.abort()\n options.signal?.addEventListener('abort', abort, { once: true })\n if (options.signal?.aborted) abort()\n\n const closed = (async () => {\n try {\n while (!controller.signal.aborted) {\n let cycle: void | WorkerCycleResult = undefined\n try {\n cycle = await options.tick(Date.now())\n } catch (error) {\n options.onError?.(toError(error))\n }\n await waitForNext(\n pollIntervalMs,\n controller.signal,\n cycle?.wake,\n options.onError,\n )\n }\n } finally {\n options.signal?.removeEventListener('abort', abort)\n await options.drain?.()\n }\n })()\n const close = () => {\n controller.abort()\n return closed\n }\n return { closed, close }\n}\n"]}
@@ -1,6 +1,9 @@
1
1
  import type { AnyDb } from '../dialect.js';
2
2
  import type { BunderstackLogger } from '../logging.js';
3
3
  import type { JobsDefs, JobsRuntimeFacade, TickResult } from './define.js';
4
+ type PumpResult = {
5
+ wake?: Promise<void>;
6
+ };
4
7
  export declare function createJobRunner(deps: {
5
8
  db: AnyDb;
6
9
  defs: JobsDefs;
@@ -9,6 +12,8 @@ export declare function createJobRunner(deps: {
9
12
  logger?: BunderstackLogger;
10
13
  }): {
11
14
  tick(now?: number): Promise<TickResult>;
15
+ pump: (now?: number) => Promise<PumpResult>;
16
+ drain: () => Promise<void>;
12
17
  inspect(now: number): Promise<{
13
18
  runnable: any;
14
19
  failed: {
@@ -30,4 +35,5 @@ export declare function createJobRunner(deps: {
30
35
  }>;
31
36
  setJobsFacade(f: JobsRuntimeFacade): void;
32
37
  };
38
+ export {};
33
39
  //# sourceMappingURL=worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/jobs/worker.ts"],"names":[],"mappings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