fix: force reload cron store
parent
5b0851ebd8
commit
6f200ea77f
|
|
@ -127,21 +127,13 @@ async function getFileMtimeMs(path: string): Promise<number | null> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensureLoaded(state: CronServiceState, opts?: { forceReload?: boolean }) {
|
export async function ensureLoaded(state: CronServiceState, opts?: { forceReload?: boolean }) {
|
||||||
// Fast path: store is already in memory. The timer path passes
|
// Fast path: store is already in memory. Other callers (add, list, run, …)
|
||||||
// forceReload=true so that cross-service writes to the same store file
|
// trust the in-memory copy to avoid a stat syscall on every operation.
|
||||||
// are always picked up. Other callers (add, list, run, …) trust the
|
|
||||||
// in-memory copy to avoid a stat syscall on every operation.
|
|
||||||
if (state.store && !opts?.forceReload) {
|
if (state.store && !opts?.forceReload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Force reload always re-reads the file to avoid missing cross-service
|
||||||
if (opts?.forceReload && state.store) {
|
// edits on filesystems with coarse mtime resolution.
|
||||||
// Only pay for the stat when we're explicitly checking for external edits.
|
|
||||||
const mtime = await getFileMtimeMs(state.deps.storePath);
|
|
||||||
if (mtime !== null && state.storeFileMtimeMs !== null && mtime === state.storeFileMtimeMs) {
|
|
||||||
return; // File unchanged since our last load/persist.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileMtimeMs = await getFileMtimeMs(state.deps.storePath);
|
const fileMtimeMs = await getFileMtimeMs(state.deps.storePath);
|
||||||
const loaded = await loadCronStore(state.deps.storePath);
|
const loaded = await loadCronStore(state.deps.storePath);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue