Skip to content

Commit 3e96fde

Browse files
committed
fix(cron): split gateway cron service contract
1 parent 94340b9 commit 3e96fde

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

‎src/cron/service-contract.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type {
2+
CronAddInput,
3+
CronAddResult,
4+
CronListResult,
5+
CronRemoveResult,
6+
CronRunMode,
7+
CronRunResult,
8+
CronStatusSummary,
9+
CronUpdateInput,
10+
CronUpdateResult,
11+
CronWakeMode,
12+
} from "./service/state.js";
13+
import type { CronJob } from "./types.js";
14+
15+
type CronJobsEnabledFilter = "all" | "enabled" | "disabled";
16+
type CronJobsSortBy = "nextRunAtMs" | "updatedAtMs" | "name";
17+
type CronSortDir = "asc" | "desc";
18+
19+
export type CronListPageOptions = {
20+
includeDisabled?: boolean;
21+
limit?: number;
22+
offset?: number;
23+
query?: string;
24+
enabled?: CronJobsEnabledFilter;
25+
sortBy?: CronJobsSortBy;
26+
sortDir?: CronSortDir;
27+
};
28+
29+
export type CronListPageResult = {
30+
jobs: CronJob[];
31+
total: number;
32+
offset: number;
33+
limit: number;
34+
hasMore: boolean;
35+
nextOffset: number | null;
36+
};
37+
38+
export type CronWakeResult = { ok: true } | { ok: false };
39+
40+
export interface CronServiceContract {
41+
start(): Promise<void>;
42+
stop(): void;
43+
status(): Promise<CronStatusSummary>;
44+
list(opts?: { includeDisabled?: boolean }): Promise<CronListResult>;
45+
listPage(opts?: CronListPageOptions): Promise<CronListPageResult>;
46+
add(input: CronAddInput): Promise<CronAddResult>;
47+
update(id: string, patch: CronUpdateInput): Promise<CronUpdateResult>;
48+
remove(id: string): Promise<CronRemoveResult>;
49+
run(id: string, mode?: CronRunMode): Promise<CronRunResult>;
50+
enqueueRun(id: string, mode?: CronRunMode): Promise<CronRunResult>;
51+
getJob(id: string): CronJob | undefined;
52+
wake(opts: { mode: CronWakeMode; text: string }): CronWakeResult;
53+
}

‎src/cron/service.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import type { CronListPageOptions, CronServiceContract } from "./service-contract.js";
12
import * as ops from "./service/ops.js";
23
import { type CronServiceDeps, createCronServiceState } from "./service/state.js";
34
import type { CronJob, CronJobCreate, CronJobPatch } from "./types.js";
45

56
export type { CronEvent, CronServiceDeps } from "./service/state.js";
7+
export type {
8+
CronListPageOptions,
9+
CronListPageResult,
10+
CronServiceContract,
11+
CronWakeResult,
12+
} from "./service-contract.js";
613

7-
export class CronService {
14+
export class CronService implements CronServiceContract {
815
private readonly state;
916
constructor(deps: CronServiceDeps) {
1017
this.state = createCronServiceState(deps);
@@ -26,7 +33,7 @@ export class CronService {
2633
return await ops.list(this.state, opts);
2734
}
2835

29-
async listPage(opts?: ops.CronListPageOptions) {
36+
async listPage(opts?: CronListPageOptions) {
3037
return await ops.listPage(this.state, opts);
3138
}
3239

‎src/gateway/server-methods/shared-types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ModelCatalogEntry } from "../../agents/model-catalog.types.js";
22
import type { CliDeps } from "../../cli/deps.types.js";
33
import type { HealthSummary } from "../../commands/health.types.js";
44
import type { OpenClawConfig } from "../../config/types.openclaw.js";
5-
import type { CronService } from "../../cron/service.js";
5+
import type { CronServiceContract } from "../../cron/service-contract.js";
66
import type { PluginApprovalRequestPayload } from "../../infra/plugin-approvals.js";
77
import type { createSubsystemLogger } from "../../logging/subsystem.js";
88
import type { WizardSession } from "../../wizard/session.js";
@@ -37,7 +37,7 @@ export type RespondFn = (
3737

3838
export type GatewayRequestContext = {
3939
deps: CliDeps;
40-
cron: CronService;
40+
cron: CronServiceContract;
4141
cronStorePath: string;
4242
execApprovalManager?: ExecApprovalManager;
4343
pluginApprovalManager?: ExecApprovalManager<PluginApprovalRequestPayload>;

0 commit comments

Comments
 (0)