diff --git a/src/cron/service-contract.ts b/src/cron/service-contract.ts index aacceb2b0c2..ee119e2e029 100644 --- a/src/cron/service-contract.ts +++ b/src/cron/service-contract.ts @@ -37,6 +37,8 @@ export type CronListPageResult = { export type CronWakeResult = { ok: true } | { ok: false }; +export type CronServiceRunResult = CronRunResult | { ok: true; ran: false; reason: "invalid-spec" }; + export interface CronServiceContract { start(): Promise; stop(): void; @@ -46,8 +48,8 @@ export interface CronServiceContract { add(input: CronAddInput): Promise; update(id: string, patch: CronUpdateInput): Promise; remove(id: string): Promise; - run(id: string, mode?: CronRunMode): Promise; - enqueueRun(id: string, mode?: CronRunMode): Promise; + run(id: string, mode?: CronRunMode): Promise; + enqueueRun(id: string, mode?: CronRunMode): Promise; getJob(id: string): CronJob | undefined; wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult; } diff --git a/src/cron/service.ts b/src/cron/service.ts index d972b2b0c0b..e1fa82d7cf3 100644 --- a/src/cron/service.ts +++ b/src/cron/service.ts @@ -1,4 +1,8 @@ -import type { CronListPageOptions, CronServiceContract } from "./service-contract.js"; +import type { + CronListPageOptions, + CronServiceContract, + CronServiceRunResult, +} from "./service-contract.js"; import * as ops from "./service/ops.js"; import { type CronServiceDeps, createCronServiceState } from "./service/state.js"; import type { CronJob, CronJobCreate, CronJobPatch } from "./types.js"; @@ -8,6 +12,7 @@ export type { CronListPageOptions, CronListPageResult, CronServiceContract, + CronServiceRunResult, CronWakeResult, } from "./service-contract.js"; @@ -49,12 +54,16 @@ export class CronService implements CronServiceContract { return await ops.remove(this.state, id); } - async run(id: string, mode?: "due" | "force") { + async run(id: string, mode?: "due" | "force"): Promise { return await ops.run(this.state, id, mode); } - async enqueueRun(id: string, mode?: "due" | "force") { - return await ops.enqueueRun(this.state, id, mode); + async enqueueRun(id: string, mode?: "due" | "force"): Promise { + const result = await ops.enqueueRun(this.state, id, mode); + if (result.ok && "runnable" in result) { + throw new Error("cron enqueueRun returned unresolved runnable disposition"); + } + return result; } getJob(id: string): CronJob | undefined { diff --git a/src/secrets/runtime-core-snapshots.test.ts b/src/secrets/runtime-core-snapshots.test.ts index 219eef9d8da..dd3f7ede5a7 100644 --- a/src/secrets/runtime-core-snapshots.test.ts +++ b/src/secrets/runtime-core-snapshots.test.ts @@ -11,6 +11,7 @@ import { } from "./runtime.js"; import { asConfig, + buildTestWebSearchProviders, loadAuthStoreWithProfiles, resetPluginWebSearchProvidersMock, } from "./runtime.test-support.ts";