Skip to content

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

chore(cron): label the first-deploy migration code for cleanup

Calvin04362e9ec066
diff --git a/backend/e2e-test/cron-job.spec.ts b/backend/e2e-test/cron-job.spec.ts
index fe3ae75970..bc7b17b06a 100644
--- a/backend/e2e-test/cron-job.spec.ts
+++ b/backend/e2e-test/cron-job.spec.ts
@@ -552,6 +552,7 @@ describe("dedup across restarts", () => {
expect(await testRedis.keys(RUN_KEYS("restart-job"))).toEqual([]);
}, 10_000);
+ // Migration, part 1 of 2 (see ENQUEUE_RUN_LUA): remove with that branch.
test("a run hash written without a last value is recorded instead of enqueued again", async () => {
const scheduledAt = currentFireMs();
await testRedis.hset(
@@ -585,9 +586,10 @@ describe("dedup across restarts", () => {
expect(await testRedis.get(LAST_KEY("new-job"))).toBe(String(fire));
}, 10_000);
- // Jobs that ran before the last key existed have no last value either. When the first deploy
- // that writes it lands just after a boundary, no pod may have enqueued that fire yet, and
- // treating the job as new would silently drop it.
+ // Migration, part 2 of 2 (see ENQUEUE_RUN_LUA): remove with that branch. Jobs that ran before
+ // the last key existed have no last value either. When the first deploy that writes it lands
+ // just after a boundary, no pod may have enqueued that fire yet, and treating the job as new
+ // would silently drop it.
test("a job with no last value still runs a fire that only just became due", async () => {
freezeClockAfterFire(100);
const handler = vi.fn().mockResolvedValue(undefined);
diff --git a/backend/src/lib/cron/cron-job.ts b/backend/src/lib/cron/cron-job.ts
index 46594639ea..c995664de5 100644
--- a/backend/src/lib/cron/cron-job.ts
+++ b/backend/src/lib/cron/cron-job.ts
@@ -61,7 +61,8 @@ const PARTICIPANT_SLOTS = 5;
const PROCESS_BATCH_SIZE = 50;
const NEXT_FIRE_BUFFER_MS = 1_000; // shared margin for fitsBeforeNextFire and jitterWindowMs
const ERROR_MESSAGE_MAX_LEN = 4_000;
-// A fire due at most this many enqueue ticks ago counts as just due: pods may not have enqueued it yet.
+// Migration only, see "Migration, part 2 of 2" in ENQUEUE_RUN_LUA. A fire due at most this many
+// enqueue ticks ago counts as just due: pods may not have enqueued it yet.
const JUST_DUE_ENQUEUE_TICKS = 2;
const DEFAULTS = {
@@ -117,17 +118,22 @@ const ENQUEUE_RUN_LUA = `
return ${EnqueueResult.AlreadyEnqueued}
end
- -- Backfill only, not scheduling logic. Pods without "lastKey" create the run hash but never
- -- set "lastKey". If the run hash exists, the fire is already enqueued, so just record it.
- -- Remove once every deployment sets "lastKey".
+ -- Migration, part 1 of 2. Not scheduling logic; remove together with part 2.
+ -- Pods without "lastKey" create the run hash but never set "lastKey". If the run hash exists,
+ -- the fire is already enqueued, so just record it. Without this, part 2 would enqueue that
+ -- fire a second time.
if redis.call('exists', runKey) == 1 then
redis.call('set', lastKey, scheduledAt)
return ${EnqueueResult.AlreadyEnqueued}
end
-- No "last" means the job has never fired. Record this fire without running it, so the next
- -- fire is the first run. A fire that "justBecameDue" still runs: on the first deploy of
+ -- fire is the first run.
+ --
+ -- Migration, part 2 of 2. A fire that "justBecameDue" still runs: on the first deploy of
-- "lastKey", existing jobs have no "last" either, and no pod may have enqueued this fire yet.
+ -- To clean up, remove part 1, the "justBecameDue" argument and JUST_DUE_ENQUEUE_TICKS, so
+ -- this check becomes "if not last then", and remove the e2e tests labelled with each part.
if not last and not justBecameDue then
redis.call('set', lastKey, scheduledAt)
return ${EnqueueResult.SkippedFirstFire}