MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / check

Function check

source code/utils/cronScheduler.ts:232–396  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

230 }
231
232 function check() {
233 if (isKilled?.()) return
234 if (isLoading() && !assistantMode) return
235 const now = Date.now()
236 const seen = new Set<string>()
237 // File-backed recurring tasks that fired this tick. Batched into one
238 // markCronTasksFired call after the loop so N fires = one write. Session
239 // tasks excluded — they die with the process, no point persisting.
240 const firedFileRecurring: string[] = []
241 // Read once per tick. REPL callers pass getJitterConfig backed by
242 // GrowthBook so a config push takes effect without restart. Daemon and
243 // SDK callers omit it and get DEFAULT_CRON_JITTER_CONFIG (safe — jitter
244 // is an ops lever for REPL fleet load-shedding, not a daemon concern).
245 const jitterCfg = getJitterConfig?.() ?? DEFAULT_CRON_JITTER_CONFIG
246
247 // Shared loop body. `isSession` routes the one-shot cleanup path:
248 // session tasks are removed synchronously from memory, file tasks go
249 // through the async removeCronTasks + chokidar reload.
250 function process(t: CronTask, isSession: boolean) {
251 if (filter && !filter(t)) return
252 seen.add(t.id)
253 if (inFlight.has(t.id)) return
254
255 let next = nextFireAt.get(t.id)
256 if (next === undefined) {
257 // First sight — anchor from lastFiredAt (recurring) or createdAt.
258 // Never-fired recurring tasks use createdAt: if isLoading delayed
259 // this tick past the fire time, anchoring from `now` would compute
260 // next-year for pinned crons (`30 14 27 2 *`). Fired-before tasks
261 // use lastFiredAt: the reschedule below writes `now` back to disk,
262 // so on next process spawn first-sight computes the SAME newNext we
263 // set in-memory here. Without this, a daemon child despawning on
264 // idle loses nextFireAt and the next spawn re-anchors from 10-day-
265 // old createdAt → fires every task every cycle.
266 next = t.recurring
267 ? (jitteredNextCronRunMs(
268 t.cron,
269 t.lastFiredAt ?? t.createdAt,
270 t.id,
271 jitterCfg,
272 ) ?? Infinity)
273 : (oneShotJitteredNextCronRunMs(
274 t.cron,
275 t.createdAt,
276 t.id,
277 jitterCfg,
278 ) ?? Infinity)
279 nextFireAt.set(t.id, next)
280 logForDebugging(
281 `[ScheduledTasks] scheduled ${t.id} for ${next === Infinity ? 'never' : new Date(next).toISOString()}`,
282 )
283 }
284
285 if (now < next) return
286
287 logForDebugging(
288 `[ScheduledTasks] firing ${t.id}${t.recurring ? ' (recurring)' : ''}`,
289 )

Callers

nothing calls this directly

Calls 9

processFunction · 0.85
markCronTasksFiredFunction · 0.85
logForDebuggingFunction · 0.85
getSessionCronTasksFunction · 0.85
deleteMethod · 0.80
keysMethod · 0.80
addMethod · 0.45
clearMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected