Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
guard upsertJobScheduler
Matheus Nogueiradf6255ec565b
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.test.ts b/backend/src/ee/services/audit-log/audit-log-queue.test.tsindex 5adf8017a8..baadb43cab 100644--- a/backend/src/ee/services/audit-log/audit-log-queue.test.ts+++ b/backend/src/ee/services/audit-log/audit-log-queue.test.ts@@ -11,7 +11,8 @@ const mockConfig = {CLICKHOUSE_AUDIT_LOG_TABLE_NAME: "audit_logs",CLICKHOUSE_AUDIT_LOG_INSERT_SETTINGS: {},AUDIT_LOG_STREAMS_ENABLED: false,- DISABLE_POSTGRES_AUDIT_LOG_STORAGE: false+ DISABLE_POSTGRES_AUDIT_LOG_STORAGE: false,+ isGeneralWorkerRunModeEnabled: true};vi.mock("@app/lib/config/env", async (importOriginal) => ({@@ -52,9 +53,10 @@ const collectResult = (payloads: Record<string, unknown>[], lastId = "9-0") => (lastId});-const createHarness = async ({ clickhouse = false, streamsEnabled = false } = {}) => {+const createHarness = async ({ clickhouse = false, streamsEnabled = false, generalWorkers = true } = {}) => {mockConfig.CLICKHOUSE_AUDIT_LOG_ENABLED = clickhouse;mockConfig.AUDIT_LOG_STREAMS_ENABLED = streamsEnabled;+ mockConfig.isGeneralWorkerRunModeEnabled = generalWorkers;const startHandlers = new Map<string, (job?: unknown) => Promise<void>>();const queueService = {@@ -137,11 +139,20 @@ beforeEach(() => {});describe("audit-log-queue construction", () => {- test("registers the batch scheduler when queue workers are enabled", async () => {+ test("registers the batch scheduler in the general-workers run mode", async () => {const { queueService } = await createHarness();expect(queueService.upsertJobScheduler).toHaveBeenCalledTimes(1);});++ test("skips scheduler registration outside the general-workers run mode", async () => {+ // An api or secret-scanning pod has no worker on this queue, so arming the 5s schedule from+ // there leaves iterations nobody drains.+ const { queueService } = await createHarness({ generalWorkers: false });++ expect(queueService.upsertJobScheduler).not.toHaveBeenCalled();+ expect(queueService.start).toHaveBeenCalledWith(QueueName.AuditLogClickHouseBatch, expect.any(Function));+ });});describe("audit-log-queue pushToLog", () => {diff --git a/backend/src/ee/services/audit-log/audit-log-queue.ts b/backend/src/ee/services/audit-log/audit-log-queue.tsindex 09f67773a4..bff2c60d18 100644--- a/backend/src/ee/services/audit-log/audit-log-queue.ts+++ b/backend/src/ee/services/audit-log/audit-log-queue.ts@@ -334,12 +334,16 @@ export const auditLogQueueServiceFactory = async ({// "audit-log-clickhouse-batch" so the existing Redis scheduler key isn't orphaned on upgrade.queueService.start(QueueName.AuditLogClickHouseBatch, consumeAuditLogStream);- await queueService.upsertJobScheduler(- QueueName.AuditLogClickHouseBatch,- `${JOB_SCHEDULER_PREFIX}:audit-log-clickhouse-batch`,- { every: 5000 },- { name: QueueJobs.AuditLogClickHouseBatch }- );+ // Only the fleet that consumes this queue arms its scheduler. An api or secret-scanning pod has+ // no worker on it, so registering from there would re-arm a 5s schedule nobody drains.+ if (getConfig().isGeneralWorkerRunModeEnabled) {+ await queueService.upsertJobScheduler(+ QueueName.AuditLogClickHouseBatch,+ `${JOB_SCHEDULER_PREFIX}:audit-log-clickhouse-batch`,+ { every: 5000 },+ { name: QueueJobs.AuditLogClickHouseBatch }+ );+ }return {pushToLog