mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:51:25 +00:00
fix(cron): persist delivered flag in job state to surface delivery failures (openclaw#19174) thanks @simonemacario
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: simonemacario <2116609+simonemacario@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -18,6 +18,7 @@ export type CronEvent = {
|
||||
status?: CronRunStatus;
|
||||
error?: string;
|
||||
summary?: string;
|
||||
delivered?: boolean;
|
||||
sessionId?: string;
|
||||
sessionKey?: string;
|
||||
nextRunAtMs?: number;
|
||||
|
||||
@@ -34,6 +34,7 @@ const DEFAULT_JOB_TIMEOUT_MS = 10 * 60_000; // 10 minutes
|
||||
type TimedCronRunOutcome = CronRunOutcome &
|
||||
CronRunTelemetry & {
|
||||
jobId: string;
|
||||
delivered?: boolean;
|
||||
startedAt: number;
|
||||
endedAt: number;
|
||||
};
|
||||
@@ -73,6 +74,7 @@ function applyJobResult(
|
||||
result: {
|
||||
status: CronRunStatus;
|
||||
error?: string;
|
||||
delivered?: boolean;
|
||||
startedAt: number;
|
||||
endedAt: number;
|
||||
},
|
||||
@@ -82,6 +84,7 @@ function applyJobResult(
|
||||
job.state.lastStatus = result.status;
|
||||
job.state.lastDurationMs = Math.max(0, result.endedAt - result.startedAt);
|
||||
job.state.lastError = result.error;
|
||||
job.state.lastDelivered = result.delivered;
|
||||
job.updatedAtMs = result.endedAt;
|
||||
|
||||
// Track consecutive errors for backoff / auto-disable.
|
||||
@@ -336,6 +339,7 @@ export async function onTimer(state: CronServiceState) {
|
||||
const shouldDelete = applyJobResult(state, job, {
|
||||
status: result.status,
|
||||
error: result.error,
|
||||
delivered: result.delivered,
|
||||
startedAt: result.startedAt,
|
||||
endedAt: result.endedAt,
|
||||
});
|
||||
@@ -486,7 +490,7 @@ export async function runDueJobs(state: CronServiceState) {
|
||||
async function executeJobCore(
|
||||
state: CronServiceState,
|
||||
job: CronJob,
|
||||
): Promise<CronRunOutcome & CronRunTelemetry> {
|
||||
): Promise<CronRunOutcome & CronRunTelemetry & { delivered?: boolean }> {
|
||||
if (job.sessionTarget === "main") {
|
||||
const text = resolveJobPayloadTextForMain(job);
|
||||
if (!text) {
|
||||
@@ -591,6 +595,7 @@ async function executeJobCore(
|
||||
status: res.status,
|
||||
error: res.error,
|
||||
summary: res.summary,
|
||||
delivered: res.delivered,
|
||||
sessionId: res.sessionId,
|
||||
sessionKey: res.sessionKey,
|
||||
model: res.model,
|
||||
@@ -619,6 +624,7 @@ export async function executeJob(
|
||||
|
||||
let coreResult: {
|
||||
status: CronRunStatus;
|
||||
delivered?: boolean;
|
||||
} & CronRunOutcome &
|
||||
CronRunTelemetry;
|
||||
try {
|
||||
@@ -631,6 +637,7 @@ export async function executeJob(
|
||||
const shouldDelete = applyJobResult(state, job, {
|
||||
status: coreResult.status,
|
||||
error: coreResult.error,
|
||||
delivered: coreResult.delivered,
|
||||
startedAt,
|
||||
endedAt,
|
||||
});
|
||||
@@ -648,6 +655,7 @@ function emitJobFinished(
|
||||
job: CronJob,
|
||||
result: {
|
||||
status: CronRunStatus;
|
||||
delivered?: boolean;
|
||||
} & CronRunOutcome &
|
||||
CronRunTelemetry,
|
||||
runAtMs: number,
|
||||
@@ -658,6 +666,7 @@ function emitJobFinished(
|
||||
status: result.status,
|
||||
error: result.error,
|
||||
summary: result.summary,
|
||||
delivered: result.delivered,
|
||||
sessionId: result.sessionId,
|
||||
sessionKey: result.sessionKey,
|
||||
runAtMs,
|
||||
|
||||
Reference in New Issue
Block a user