openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.43 kB
JavaScript
import{a as getSqliteWorkerStateContext}from"./sqlite-worker-state-context-DJ4guxKh.mjs";import{l as runOpenClawStateWriteTransaction}from"./openclaw-state-db-BlgxYkYw.mjs";import{i as ownsCronSource,n as cronSourceIdentity,o as setCronSourceIdentity}from"./source-schedule-D7cVsqMy.mjs";import{t as createCronMutationLogger}from"./runtime-mutation.worker-72fWR0tW.mjs";import{r as resolveFailureAlert}from"./failure-alerts-CBth-ws-.mjs";import{t as applyJobResult}from"./timer-outcomes-D3FrzcP1.mjs";import{t as mutateCronRuntimeRowsInDatabase}from"./runtime-rows.kernel-J9rQr_fK.mjs";
//!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,defaultAgentId:s}=r;const c={deps:{nowMs:()=>e,cronConfig:o,defaultAgentId:s,log:createCronMutationLogger(i.logs)},preparedFailureAlert:{jobId:t.jobId,value:resolveFailureAlert({deps:{cronConfig:o,defaultAgentId:s}},n)}};n.state.consecutiveErrors=Math.max(n.state.consecutiveErrors??0,4);applyJobResult(c,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]})}export{mutateCronExternalStateInWorker};