Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

keep old log

Thiago Araujo da Silva048a2ac9c23d
diff --git a/backend/src/lib/cron/cron-job.test.ts b/backend/src/lib/cron/cron-job.test.ts
index 56bb70ec0c..2a671dc00f 100644
--- a/backend/src/lib/cron/cron-job.test.ts
+++ b/backend/src/lib/cron/cron-job.test.ts
@@ -1,5 +1,7 @@
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import { logger } from "@app/lib/logger";
+
import { cronJobFactory } from "./cron-job";
vi.mock("@app/lib/logger", () => ({
@@ -317,6 +319,27 @@ describe("slot election", () => {
expect([...held.keys()]).toEqual(["{cron}:slot:0"]);
await stop();
});
+
+ // These two strings are what alerting matches on, so pin them. The initial
+ // claim and the periodic refresh share one code path now, and it would be easy
+ // to collapse them into a single message without noticing.
+ test("slot failures are logged under their own labels", async () => {
+ const redis = makeRedis();
+ redis.set.mockRejectedValue(new Error("redis unavailable"));
+ const { start, stop } = makeFactory({ redis });
+ vi.mocked(logger.error).mockClear();
+
+ start(); // initial claim fails
+ await flushSlotOps();
+ vi.advanceTimersByTime(50); // refresh tick fails
+ await flushSlotOps();
+
+ const messages = vi.mocked(logger.error).mock.calls.map(([, message]) => message);
+ expect(messages).toContain("cron: initial slot claim failed");
+ expect(messages).toContain("cron: slot refresh failed");
+
+ await stop();
+ });
});
describe("claim and execute", () => {
diff --git a/backend/src/lib/cron/cron-job.ts b/backend/src/lib/cron/cron-job.ts
index 72eabf1e33..ad31aa629b 100644
--- a/backend/src/lib/cron/cron-job.ts
+++ b/backend/src/lib/cron/cron-job.ts
@@ -378,10 +378,10 @@ export const cronJobFactory = ({
// Chaining also gives stop() one handle to await, so it can never read
// `currentSlot` mid-handover (skipping the release) or have a late claim land
// after the release.
- const runSlotOp = () => {
+ const runSlotOp = (label: string) => {
slotOp = slotOp
.then(() => (stopped ? undefined : claimOrRefreshSlot()))
- .catch((err: unknown) => logger.error({ err }, "cron: slot refresh failed"));
+ .catch((err: unknown) => logger.error({ err }, `cron: ${label} failed`));
return slotOp;
};
@@ -576,10 +576,10 @@ export const cronJobFactory = ({
// participating.
const start = () => {
stopped = false;
- slotTimer = setInterval(() => void runSlotOp(), slotRefreshMs);
+ slotTimer = setInterval(() => void runSlotOp("slot refresh"), slotRefreshMs);
enqueueTimer = setInterval(safeTick("enqueue tick", enqueueTick), enqueueIntervalMs);
processTimer = setInterval(safeTick("process tick", processTick), processIntervalMs);
- void runSlotOp();
+ void runSlotOp("initial slot claim");
};
// Stops the timers, drains in-flight handlers, and atomically releases the