fix(cron): split gateway cron service contract

This commit is contained in:
Vincent Koc
2026-04-12 03:51:11 +01:00
parent 94340b9598
commit 3e96fdea9f
3 changed files with 64 additions and 4 deletions

View File

@@ -0,0 +1,53 @@
import type {
CronAddInput,
CronAddResult,
CronListResult,
CronRemoveResult,
CronRunMode,
CronRunResult,
CronStatusSummary,
CronUpdateInput,
CronUpdateResult,
CronWakeMode,
} from "./service/state.js";
import type { CronJob } from "./types.js";
type CronJobsEnabledFilter = "all" | "enabled" | "disabled";
type CronJobsSortBy = "nextRunAtMs" | "updatedAtMs" | "name";
type CronSortDir = "asc" | "desc";
export type CronListPageOptions = {
includeDisabled?: boolean;
limit?: number;
offset?: number;
query?: string;
enabled?: CronJobsEnabledFilter;
sortBy?: CronJobsSortBy;
sortDir?: CronSortDir;
};
export type CronListPageResult = {
jobs: CronJob[];
total: number;
offset: number;
limit: number;
hasMore: boolean;
nextOffset: number | null;
};
export type CronWakeResult = { ok: true } | { ok: false };
export interface CronServiceContract {
start(): Promise<void>;
stop(): void;
status(): Promise<CronStatusSummary>;
list(opts?: { includeDisabled?: boolean }): Promise<CronListResult>;
listPage(opts?: CronListPageOptions): Promise<CronListPageResult>;
add(input: CronAddInput): Promise<CronAddResult>;
update(id: string, patch: CronUpdateInput): Promise<CronUpdateResult>;
remove(id: string): Promise<CronRemoveResult>;
run(id: string, mode?: CronRunMode): Promise<CronRunResult>;
enqueueRun(id: string, mode?: CronRunMode): Promise<CronRunResult>;
getJob(id: string): CronJob | undefined;
wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult;
}

View File

@@ -1,10 +1,17 @@
import type { CronListPageOptions, CronServiceContract } 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";
export type { CronEvent, CronServiceDeps } from "./service/state.js";
export type {
CronListPageOptions,
CronListPageResult,
CronServiceContract,
CronWakeResult,
} from "./service-contract.js";
export class CronService {
export class CronService implements CronServiceContract {
private readonly state;
constructor(deps: CronServiceDeps) {
this.state = createCronServiceState(deps);
@@ -26,7 +33,7 @@ export class CronService {
return await ops.list(this.state, opts);
}
async listPage(opts?: ops.CronListPageOptions) {
async listPage(opts?: CronListPageOptions) {
return await ops.listPage(this.state, opts);
}

View File

@@ -2,7 +2,7 @@ import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js";
import type { CliDeps } from "../../cli/deps.types.js";
import type { HealthSummary } from "../../commands/health.types.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import type { CronService } from "../../cron/service.js";
import type { CronServiceContract } from "../../cron/service-contract.js";
import type { PluginApprovalRequestPayload } from "../../infra/plugin-approvals.js";
import type { createSubsystemLogger } from "../../logging/subsystem.js";
import type { WizardSession } from "../../wizard/session.js";
@@ -37,7 +37,7 @@ export type RespondFn = (
export type GatewayRequestContext = {
deps: CliDeps;
cron: CronService;
cron: CronServiceContract;
cronStorePath: string;
execApprovalManager?: ExecApprovalManager;
pluginApprovalManager?: ExecApprovalManager<PluginApprovalRequestPayload>;