mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:41:22 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -8,11 +8,17 @@ import { ensureLoaded, persist } from "./store.js";
|
||||
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
||||
|
||||
export function armTimer(state: CronServiceState) {
|
||||
if (state.timer) clearTimeout(state.timer);
|
||||
if (state.timer) {
|
||||
clearTimeout(state.timer);
|
||||
}
|
||||
state.timer = null;
|
||||
if (!state.deps.cronEnabled) return;
|
||||
if (!state.deps.cronEnabled) {
|
||||
return;
|
||||
}
|
||||
const nextAt = nextWakeAtMs(state);
|
||||
if (!nextAt) return;
|
||||
if (!nextAt) {
|
||||
return;
|
||||
}
|
||||
const delay = Math.max(nextAt - state.deps.nowMs(), 0);
|
||||
// Avoid TimeoutOverflowWarning when a job is far in the future.
|
||||
const clampedDelay = Math.min(delay, MAX_TIMEOUT_MS);
|
||||
@@ -25,7 +31,9 @@ export function armTimer(state: CronServiceState) {
|
||||
}
|
||||
|
||||
export async function onTimer(state: CronServiceState) {
|
||||
if (state.running) return;
|
||||
if (state.running) {
|
||||
return;
|
||||
}
|
||||
state.running = true;
|
||||
try {
|
||||
await locked(state, async () => {
|
||||
@@ -40,11 +48,17 @@ export async function onTimer(state: CronServiceState) {
|
||||
}
|
||||
|
||||
export async function runDueJobs(state: CronServiceState) {
|
||||
if (!state.store) return;
|
||||
if (!state.store) {
|
||||
return;
|
||||
}
|
||||
const now = state.deps.nowMs();
|
||||
const due = state.store.jobs.filter((j) => {
|
||||
if (!j.enabled) return false;
|
||||
if (typeof j.state.runningAtMs === "number") return false;
|
||||
if (!j.enabled) {
|
||||
return false;
|
||||
}
|
||||
if (typeof j.state.runningAtMs === "number") {
|
||||
return false;
|
||||
}
|
||||
const next = j.state.nextRunAtMs;
|
||||
return typeof next === "number" && now >= next;
|
||||
});
|
||||
@@ -199,10 +213,13 @@ export async function executeJob(
|
||||
job,
|
||||
message: job.payload.message,
|
||||
});
|
||||
if (res.status === "ok") await finish("ok", undefined, res.summary, res.outputText);
|
||||
else if (res.status === "skipped")
|
||||
if (res.status === "ok") {
|
||||
await finish("ok", undefined, res.summary, res.outputText);
|
||||
} else if (res.status === "skipped") {
|
||||
await finish("skipped", undefined, res.summary, res.outputText);
|
||||
else await finish("error", res.error ?? "cron job failed", res.summary, res.outputText);
|
||||
} else {
|
||||
await finish("error", res.error ?? "cron job failed", res.summary, res.outputText);
|
||||
}
|
||||
} catch (err) {
|
||||
await finish("error", String(err));
|
||||
} finally {
|
||||
@@ -219,7 +236,9 @@ export function wake(
|
||||
opts: { mode: "now" | "next-heartbeat"; text: string },
|
||||
) {
|
||||
const text = opts.text.trim();
|
||||
if (!text) return { ok: false } as const;
|
||||
if (!text) {
|
||||
return { ok: false } as const;
|
||||
}
|
||||
state.deps.enqueueSystemEvent(text);
|
||||
if (opts.mode === "now") {
|
||||
state.deps.requestHeartbeatNow({ reason: "wake" });
|
||||
@@ -228,7 +247,9 @@ export function wake(
|
||||
}
|
||||
|
||||
export function stopTimer(state: CronServiceState) {
|
||||
if (state.timer) clearTimeout(state.timer);
|
||||
if (state.timer) {
|
||||
clearTimeout(state.timer);
|
||||
}
|
||||
state.timer = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user