Skip to content

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

disable crons if general-workers are not running in instance

Matheus Nogueirafc2621ab2ac4
diff --git a/backend/src/lib/cron/cron-job.ts b/backend/src/lib/cron/cron-job.ts
index 8505edab41..cb92be8ca6 100644
--- a/backend/src/lib/cron/cron-job.ts
+++ b/backend/src/lib/cron/cron-job.ts
@@ -172,7 +172,8 @@ export const cronJobFactory = ({
retryBackoffBaseMs = DEFAULTS.retryBackoffBaseMs,
retryBackoffMaxMs = DEFAULTS.retryBackoffMaxMs,
drainTimeoutMs = DEFAULTS.drainTimeoutMs,
- keyPrefix = KEY_HASH_TAG
+ keyPrefix = KEY_HASH_TAG,
+ schedulingEnabled = true
}: {
redis: Redis | Cluster;
redlock: Redlock;
@@ -192,6 +193,12 @@ export const cronJobFactory = ({
* server's real one can share a Redis without colliding on slot keys.
*/
keyPrefix?: string;
+ /**
+ * Whether this pod runs cron handlers at all. When false, `register` is a no-op, so a pod that
+ * never starts the timers also never holds the registry. Defaults to true so tests and any
+ * caller that only wants the manager keep the previous behaviour.
+ */
+ schedulingEnabled?: boolean;
}) => {
assertHashTagged(keyPrefix);
@@ -200,6 +207,10 @@ export const cronJobFactory = ({
const LEASE_KEY = (id: string) => `${keyPrefix}:lease:${id}`;
const PENDING_ZSET = `${keyPrefix}:pending`;
+ if (!schedulingEnabled) {
+ logger.info("cron: scheduling disabled for this run mode, skipping every registration");
+ }
+
const workerId = randomUUID();
const entries = new Map<string, CronEntry>();
const lastEnqueuedAt = new Map<string, number>();
@@ -323,6 +334,8 @@ export const cronJobFactory = ({
handlerTimeoutMs?: number;
leaseDurationMs?: number;
}) => {
+ if (!schedulingEnabled) return;
+
if (!enabled) {
logger.info(`cron[${name}]: disabled`);
return;
diff --git a/backend/src/queue/queue-service.ts b/backend/src/queue/queue-service.ts
index c1ec85a5ea..53c6101a40 100644
--- a/backend/src/queue/queue-service.ts
+++ b/backend/src/queue/queue-service.ts
@@ -734,7 +734,13 @@ export const queueServiceFactory = (redisCfg: TRedisConfigKeys): TQueueServiceFa
// Remove orphaned job schedulers left in Redis by deleted queues.
// Queues migrated to the cronJob system (cron-job.ts) are listed here so their
// BullMQ schedulers and pending jobs are cleaned up on first boot of the new image.
+ //
+ // Gated to general-workers because every name below belongs to that fleet, and obliterate() is
+ // called with force, which deletes active jobs too. Reaping is the consuming pod's job: an API
+ // pod has no worker on these queues and must not clear work another pod is running.
void (async () => {
+ if (!getConfig().isGeneralWorkerRunModeEnabled) return;
+
const staleQueueNames = [
"queue-internal-recovery",
"queue-internal-reconciliation",
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 8a43ff4b70..9f2f5999ec 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -584,7 +584,7 @@ export const registerRoutes = async (
const appCfg = getConfig();
const redlock = new Redlock([redis], { retryCount: 0 });
- const cronJob = cronJobFactory({ redis, redlock });
+ const cronJob = cronJobFactory({ redis, redlock, schedulingEnabled: envConfig.isGeneralWorkerRunModeEnabled });
if (envConfig.isGeneralWorkerRunModeEnabled) {
cronJob.start();
}