UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

86 lines (85 loc) • 3.06 kB
import { a as getSqliteWorkerStateContext } from "./sqlite-worker-state-context-CR8h__Vh.mjs"; import { l as runOpenClawStateWriteTransaction } from "./openclaw-state-db-ARhwdPJg.mjs"; import { i as ownsCronSource, n as cronSourceIdentity, o as setCronSourceIdentity } from "./source-schedule-DlDKIQwQ.mjs"; import { t as createCronMutationLogger } from "./runtime-mutation.worker-CnJDZp_q.mjs"; import { r as resolveFailureAlert } from "./failure-alerts-DTfFZTS2.mjs"; import { t as applyJobResult } from "./timer-outcomes-CE8Zvd7s.mjs"; import { t as mutateCronRuntimeRowsInDatabase } from "./runtime-rows.kernel-DLiVou2I.mjs"; //#region src/cron/store/external-state.worker.ts function mutateCronExternalStateInWorker(e, t) { return runOpenClawStateWriteTransaction(({ db: e }) => { return { outcome: mutateCronRuntimeRowsInDatabase({ database: e, storeKey: t.storeKey, jobIds: /* @__PURE__ */ new Set([t.jobId]), mutate({ jobs: e }) { const n = e.get(t.jobId); const r = t.snapshot; const i = { nowMs: r.nowMs, notifications: [], logs: [] }; if (!n) return { value: i }; const { change: a } = t; if (a.kind !== "counters" && a.source && !ownsCronSource(n, a.source.scheduleKey, a.source.identity)) return { value: i }; switch (a.kind) { case "state": case "failure": { const e = cronSourceIdentity(n); Object.assign(n.state, a.statePatch); setCronSourceIdentity(n, e); if (a.kind === "failure") { const { nowMs: e, cronConfig: o } = r; const s = { deps: { nowMs: () => e, cronConfig: o, log: createCronMutationLogger(i.logs) }, preparedFailureAlert: { jobId: t.jobId, value: resolveFailureAlert({ deps: { cronConfig: o } }, n) } }; n.state.consecutiveErrors = Math.max(n.state.consecutiveErrors ?? 0, 4); applyJobResult(s, n, { status: "error", error: a.error, errorReason: void 0, executionStarted: false, startedAt: e, endedAt: e }, { deferredNotifications: i.notifications }); n.state.nextRunAtMs = void 0; } break; } case "retire": setCronSourceIdentity(n, a.nextIdentity); break; case "counters": if (n.schedule.kind !== "stream") return { value: i }; n.state.streamDroppedBatches = Math.max(n.state.streamDroppedBatches ?? 0, a.counters.streamDroppedBatches ?? 0); n.state.streamCoalescedBatches = Math.max(n.state.streamCoalescedBatches ?? 0, a.counters.streamCoalescedBatches ?? 0); } i.job = n; return { upsertJobIds: [n.id], value: i }; } }).value }; }, { database: e, path: e.path, env: getSqliteWorkerStateContext().environment }, { operationLabel: { state: "cron.external-state", retire: "cron.retire-stream-source", counters: "cron.external-counters", failure: "cron.external-failure" }[t.change.kind] }); } //#endregion export { mutateCronExternalStateInWorker };