Skip to content

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

fix: uncapped redis memory usage due to bullmq scheduler

Tre Dubravae903670eb7ce
diff --git a/backend/package-lock.json b/backend/package-lock.json
index 587b5558fd..f89d7513b0 100644
--- a/backend/package-lock.json
+++ b/backend/package-lock.json
@@ -75,7 +75,7 @@
"axios-retry": "^4.0.0",
"bcrypt": "^5.1.1",
"botbuilder": "^4.23.2",
- "bullmq": "^5.4.2",
+ "bullmq": "^5.67.3",
"cassandra-driver": "^4.7.2",
"connect-redis": "^7.1.1",
"cron": "^3.1.7",
@@ -6240,9 +6240,10 @@
"optional": true
},
"node_modules/@ioredis/commands": {
- "version": "1.2.0",
- "resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz",
- "integrity": "sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg=="
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.5.0.tgz",
+ "integrity": "sha512-eUgLqrMf8nJkZxT24JvVRrQya1vZkQh8BBeYNwGDqa5I0VUi8ACx7uFvAaLxintokpTenkK6DASvo/bvNbBGow==",
+ "license": "MIT"
},
"node_modules/@isaacs/cliui": {
"version": "8.0.2",
@@ -6974,72 +6975,78 @@
}
},
"node_modules/@msgpackr-extract/msgpackr-extract-darwin-arm64": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.2.tgz",
- "integrity": "sha512-9bfjwDxIDWmmOKusUcqdS4Rw+SETlp9Dy39Xui9BEGEk19dDwH0jhipwFzEff/pFg95NKymc6TOTbRKcWeRqyQ==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-3.0.3.tgz",
+ "integrity": "sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw==",
"cpu": [
"arm64"
],
+ "license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-darwin-x64": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.2.tgz",
- "integrity": "sha512-lwriRAHm1Yg4iDf23Oxm9n/t5Zpw1lVnxYU3HnJPTi2lJRkKTrps1KVgvL6m7WvmhYVt/FIsssWay+k45QHeuw==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-x64/-/msgpackr-extract-darwin-x64-3.0.3.tgz",
+ "integrity": "sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw==",
"cpu": [
"x64"
],
+ "license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-arm": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.2.tgz",
- "integrity": "sha512-MOI9Dlfrpi2Cuc7i5dXdxPbFIgbDBGgKR5F2yWEa6FVEtSWncfVNKW5AKjImAQ6CZlBK9tympdsZJ2xThBiWWA==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm/-/msgpackr-extract-linux-arm-3.0.3.tgz",
+ "integrity": "sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw==",
"cpu": [
"arm"
],
+ "license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-arm64": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.2.tgz",
- "integrity": "sha512-FU20Bo66/f7He9Fp9sP2zaJ1Q8L9uLPZQDub/WlUip78JlPeMbVL8546HbZfcW9LNciEXc8d+tThSJjSC+tmsg==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-arm64/-/msgpackr-extract-linux-arm64-3.0.3.tgz",
+ "integrity": "sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg==",
"cpu": [
"arm64"
],
+ "license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-linux-x64": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.2.tgz",
- "integrity": "sha512-gsWNDCklNy7Ajk0vBBf9jEx04RUxuDQfBse918Ww+Qb9HCPoGzS+XJTLe96iN3BVK7grnLiYghP/M4L8VsaHeA==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-3.0.3.tgz",
+ "integrity": "sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg==",
"cpu": [
"x64"
],
+ "license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@msgpackr-extract/msgpackr-extract-win32-x64": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.2.tgz",
- "integrity": "sha512-O+6Gs8UeDbyFpbSh2CPEz/UOrrdWPTBYNblZK5CxxLisYt4kGX3Sc+czffFonyjiGSq3jWLwJS/CCJc7tBr4sQ==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-win32-x64/-/msgpackr-extract-win32-x64-3.0.3.tgz",
+ "integrity": "sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ==",
"cpu": [
"x64"
],
+ "license": "MIT",
"optional": true,
"os": [
"win32"
@@ -13776,31 +13783,18 @@
}
},
"node_modules/bullmq": {
- "version": "5.4.2",
- "resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.4.2.tgz",
- "integrity": "sha512-dkR/KGUw18miLe3QWtvSlmGvEe08aZF+w1jZyqEHMWFW3RP4162qp6OGud0/QCAOjusiRI8UOxUhbnortPY+rA==",
- "dependencies": {
- "cron-parser": "^4.6.0",
- "ioredis": "^5.3.2",
- "lodash": "^4.17.21",
- "msgpackr": "^1.10.1",
- "node-abort-controller": "^3.1.1",
- "semver": "^7.5.4",
- "tslib": "^2.0.0",
- "uuid": "^9.0.0"
- }
- },
- "node_modules/bullmq/node_modules/uuid": {
- "version": "9.0.1",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
- "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
+ "version": "5.71.0",
+ "resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.71.0.tgz",
+ "integrity": "sha512-aeNWh4drsafSKnAJeiNH/nZP/5O8ZdtdMbnOPZmpjXj7NZUP5YC901U3bIH41iZValm7d1i3c34ojv7q31m30w==",
"license": "MIT",
- "bin": {
- "uuid": "dist/bin/uuid"
+ "dependencies": {
+ "cron-parser": "4.9.0",
+ "ioredis": "5.9.3",
+ "msgpackr": "1.11.5",
+ "node-abort-controller": "3.1.1",
+ "semver": "7.7.4",
+ "tslib": "2.8.1",
+ "uuid": "11.1.0"
}
},
"node_modules/bundle-name": {
@@ -18102,11 +18096,12 @@
}
},
"node_modules/ioredis": {
- "version": "5.3.2",
- "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.3.2.tgz",
- "integrity": "sha512-1DKMMzlIHM02eBBVOFQ1+AolGjs6+xEcM4PDL7NqOS6szq7H9jSaEkIUH6/a5Hl241LzW6JLSiAbNvTQjUupUA==",
+ "version": "5.9.3",
+ "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.9.3.tgz",
+ "integrity": "sha512-VI5tMCdeoxZWU5vjHWsiE/Su76JGhBvWF1MJnV9ZtGltHk9BmD48oDq8Tj8haZ85aceXZMxLNDQZRVo5QKNgXA==",
+ "license": "MIT",
"dependencies": {
- "@ioredis/commands": "^1.1.1",
+ "@ioredis/commands": "1.5.0",
"cluster-key-slot": "^1.1.0",
"debug": "^4.3.4",
"denque": "^2.1.0",
@@ -20184,32 +20179,34 @@
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/msgpackr": {
- "version": "1.10.1",
- "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.10.1.tgz",
- "integrity": "sha512-r5VRLv9qouXuLiIBrLpl2d5ZvPt8svdQTl5/vMvE4nzDMyEX4sgW5yWhuBBj5UmgwOTWj8CIdSXn5sAfsHAWIQ==",
+ "version": "1.11.5",
+ "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.11.5.tgz",
+ "integrity": "sha512-UjkUHN0yqp9RWKy0Lplhh+wlpdt9oQBYgULZOiFhV3VclSF1JnSQWZ5r9gORQlNYaUKQoR8itv7g7z1xDDuACA==",
+ "license": "MIT",
"optionalDependencies": {
"msgpackr-extract": "^3.0.2"
}
},
"node_modules/msgpackr-extract": {
- "version": "3.0.2",
- "resolved": "https://registry.npmjs.org/msgpackr-extract/-/msgpackr-extract-3.0.2.tgz",
- "integrity": "sha512-SdzXp4kD/Qf8agZ9+iTu6eql0m3kWm1A2y1hkpTeVNENutaB0BwHlSvAIaMxwntmRUAUjon2V4L8Z/njd0Ct8A==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/msgpackr-extract/-/msgpackr-extract-3.0.3.tgz",
+ "integrity": "sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA==",
"hasInstallScript": true,
+ "license": "MIT",
"optional": true,
"dependencies": {
- "node-gyp-build-optional-packages": "5.0.7"
+ "node-gyp-build-optional-packages": "5.2.2"
},
"bin": {
"download-msgpackr-prebuilds": "bin/download-prebuilds.js"
},
"optionalDependencies": {
- "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.2",
- "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.2",
- "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.2",
- "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.2",
- "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.2",
- "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.2"
+ "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.3",
+ "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.3",
+ "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.3",
+ "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.3",
+ "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.3",
+ "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.3"
}
},
"node_modules/mylas": {
@@ -20531,10 +20528,14 @@
}
},
"node_modules/node-gyp-build-optional-packages": {
- "version": "5.0.7",
- "resolved": "https://registry.npmjs.org/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.0.7.tgz",
- "integrity": "sha512-YlCCc6Wffkx0kHkmam79GKvDQ6x+QZkMjFGrIMxgFNILFvGSbCp2fCBC55pGTT9gVaz8Na5CLmxt/urtzRv36w==",
+ "version": "5.2.2",
+ "resolved": "https://registry.npmjs.org/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.2.2.tgz",
+ "integrity": "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw==",
+ "license": "MIT",
"optional": true,
+ "dependencies": {
+ "detect-libc": "^2.0.1"
+ },
"bin": {
"node-gyp-build-optional-packages": "bin.js",
"node-gyp-build-optional-packages-optional": "optional.js",
@@ -25538,9 +25539,9 @@
"integrity": "sha512-xXR3KGeoxTNWPD4aBvL5NUpMTT7WMANr3EWnaS190QVkY52lqqcVRD7Q05UVbBhiWDGWMlJEUam9m7uFFGVScw=="
},
"node_modules/semver": {
- "version": "7.7.3",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
- "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
+ "version": "7.7.4",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
+ "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
diff --git a/backend/package.json b/backend/package.json
index 11f7321ab5..6b240d451f 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -190,7 +190,7 @@
"axios-retry": "^4.0.0",
"bcrypt": "^5.1.1",
"botbuilder": "^4.23.2",
- "bullmq": "^5.4.2",
+ "bullmq": "^5.67.3",
"cassandra-driver": "^4.7.2",
"connect-redis": "^7.1.1",
"cron": "^3.1.7",
diff --git a/backend/src/ee/services/audit-log/audit-log-queue.ts b/backend/src/ee/services/audit-log/audit-log-queue.ts
index a0b3721eab..40f8b10184 100644
--- a/backend/src/ee/services/audit-log/audit-log-queue.ts
+++ b/backend/src/ee/services/audit-log/audit-log-queue.ts
@@ -176,15 +176,12 @@ export const auditLogQueueServiceFactory = async ({
});
// Schedule repeatable job every 5 seconds
- await queueService.queue(QueueName.AuditLogClickHouseBatch, QueueJobs.AuditLogClickHouseBatch, undefined, {
- jobId: "audit-log-clickhouse-batch",
- repeat: {
- every: 5000,
- key: "audit-log-clickhouse-batch"
- },
- removeOnFail: true,
- removeOnComplete: true
- });
+ await queueService.upsertJobScheduler(
+ QueueName.AuditLogClickHouseBatch,
+ "audit-log-clickhouse-batch",
+ { every: 5000 },
+ { name: QueueJobs.AuditLogClickHouseBatch }
+ );
}
return {
diff --git a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
index 974d25a526..fee084831b 100644
--- a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
+++ b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
@@ -250,7 +250,7 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
// only add to retry queue if this is not a retry, and if the error is not a DisableRotationErrors error
if (!isRetry && !(error instanceof DisableRotationErrors)) {
// if revocation fails, we should stop the job and queue a new job to retry the revocation at a later time.
- await queueService.stopRepeatableJobByJobId(QueueName.DynamicSecretRevocation, jobId);
+ await queueService.stopJobById(QueueName.DynamicSecretRevocation, jobId);
await queueFailedRevocation(leaseId, dynamicSecretId);
// if its the last attempt, and the error isn't a DisableRotationErrors error, send an email to the project admins (debounced)
@@ -260,7 +260,7 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
// the ID of the revocation job is set to the leaseId, so we can use that to stop the job
// we dont have to stop the retry job, because if we hit this point, its the last attempt and the retry job will be stopped by pgboss itself after this point,
- await queueService.stopRepeatableJobByJobId(QueueName.DynamicSecretRevocation, leaseId);
+ await queueService.stopJobById(QueueName.DynamicSecretRevocation, leaseId);
await $queueDynamicSecretLeaseRevocationFailedEmail(leaseId, dynamicSecretId);
}
@@ -268,7 +268,7 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
}
if (error instanceof DisableRotationErrors) {
if (jobId) {
- await queueService.stopRepeatableJobByJobId(QueueName.DynamicSecretRevocation, jobId);
+ await queueService.stopJobById(QueueName.DynamicSecretRevocation, jobId);
}
} else {
// propagate to next part
@@ -322,7 +322,6 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
logger.error(error, "Failed to send dynamic secret lease revocation failed email");
if (error instanceof DisableRotationErrors) {
if (jobId) {
- await queueService.stopRepeatableJobByJobId(QueueName.DynamicSecretLeaseRevocationFailedEmail, jobId);
await queueService.stopJobById(QueueName.DynamicSecretLeaseRevocationFailedEmail, jobId);
}
} else {
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts b/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts
index f98ad7e845..7513ffc831 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-queue.ts
@@ -118,16 +118,14 @@ export const pamDiscoveryQueueFactory = ({
}
});
+ // runs every day at 3:00 AM
void queueService
- .queue(QueueName.PamDiscoveryScan, QueueJobs.PamDiscoveryScheduledScan, undefined, {
- repeat: {
- // runs every day at 3:00 AM
- pattern: "0 3 * * *",
- utc: true,
- key: "pam-discovery-scheduled-scan"
- },
- jobId: "pam-discovery-scheduled-scan-cron"
- })
+ .upsertJobScheduler(
+ QueueName.PamDiscoveryScan,
+ "pam-discovery-scheduled-scan",
+ { pattern: "0 3 * * *" },
+ { name: QueueJobs.PamDiscoveryScheduledScan }
+ )
.catch((err) => logger.error(err, "Failed to schedule PAM Discovery cron"));
};
diff --git a/backend/src/ee/services/pki-discovery/pki-discovery-queue.ts b/backend/src/ee/services/pki-discovery/pki-discovery-queue.ts
index 47a090a3a3..e5279dd390 100644
--- a/backend/src/ee/services/pki-discovery/pki-discovery-queue.ts
+++ b/backend/src/ee/services/pki-discovery/pki-discovery-queue.ts
@@ -101,14 +101,12 @@ export const pkiDiscoveryQueueFactory = ({
});
void queueService
- .queue(QueueName.PkiDiscoveryScan, QueueJobs.PkiDiscoveryScheduledScan, undefined, {
- repeat: {
- pattern: "0 2 * * *",
- utc: true,
- key: "pki-discovery-scheduled-scan"
- },
- jobId: "pki-discovery-scheduled-scan-cron"
- })
+ .upsertJobScheduler(
+ QueueName.PkiDiscoveryScan,
+ "pki-discovery-scheduled-scan",
+ { pattern: "0 2 * * *" },
+ { name: QueueJobs.PkiDiscoveryScheduledScan }
+ )
.catch((err) => logger.error(err, "Failed to schedule PKI discovery cron"));
};
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-queue.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-queue.ts
index 63e9059888..018add5c2e 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-queue.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-queue.ts
@@ -186,11 +186,10 @@ export const secretRotationV2QueueServiceFactory = async ({
}
});
- await queueService.queue(QueueName.SecretRotationV2, QueueJobs.SecretRotationV2QueueRotations, undefined, {
- jobId: "secret-rotation-v2-cron",
- repeat: {
- pattern: appCfg.isRotationDevelopmentMode ? "* * * * *" : "0 0 * * *",
- key: "secret-rotation-v2-cron"
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.SecretRotationV2,
+ "secret-rotation-v2-cron",
+ { pattern: appCfg.isRotationDevelopmentMode ? "* * * * *" : "0 0 * * *" },
+ { name: QueueJobs.SecretRotationV2QueueRotations }
+ );
};
diff --git a/backend/src/queue/queue-service.ts b/backend/src/queue/queue-service.ts
index dcc4e5f4ca..5f03f19864 100644
--- a/backend/src/queue/queue-service.ts
+++ b/backend/src/queue/queue-service.ts
@@ -1,4 +1,4 @@
-import { Job, Queue, QueueOptions, RepeatOptions, Worker, WorkerListener } from "bullmq";
+import { Job, JobSchedulerJson, Queue, QueueOptions, RepeatOptions, Worker, WorkerListener } from "bullmq";
import { SecretEncryptionAlgo, SecretKeyEncoding, TQueueJobs } from "@app/db/schemas";
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
@@ -191,6 +191,7 @@ export type TQueueOptions = {
type: "exponential" | "fixed";
delay: number;
};
+ /** @deprecated Use upsertJobScheduler instead. */
repeat?: {
pattern?: string;
every?: number;
@@ -599,27 +600,47 @@ export type TQueueServiceFactory = {
opts: TQueueOptions
) => Promise<void>;
shutdown: () => Promise<void>;
+ /** @deprecated Use removeJobScheduler instead. */
stopRepeatableJob: <T extends QueueName>(
name: T,
job: TQueueJobTypes[T]["name"],
repeatOpt: RepeatOptions,
jobId?: string
) => Promise<boolean | undefined>;
+ /** @deprecated Use stopJobById for delayed jobs, or removeJobScheduler for schedulers. */
stopRepeatableJobByJobId: <T extends QueueName>(name: T, jobId: string) => Promise<boolean>;
+ /** @deprecated Use removeJobScheduler instead. */
stopRepeatableJobByKey: <T extends QueueName>(name: T, repeatJobKey: string) => Promise<boolean>;
clearQueue: (name: QueueName) => Promise<void>;
stopJobById: <T extends QueueName>(name: T, jobId: string) => Promise<void | undefined>;
+ /** @deprecated Use getJobSchedulers instead. */
getRepeatableJobs: (
name: QueueName,
startOffset?: number,
endOffset?: number
- ) => Promise<{ key: string; name: string; id: string | null }[]>;
+ ) => Promise<{ key: string; name: string; id?: string | null }[]>;
getDelayedJobs: (
name: QueueName,
startOffset?: number,
endOffset?: number
) => Promise<{ delay: number; timestamp: number; repeatJobKey?: string; data?: unknown }[]>;
updateJobHeartbeat: <T extends QueueName>(queueName: T, jobId: string) => Promise<void>;
+ upsertJobScheduler: <T extends QueueName>(
+ name: T,
+ schedulerId: string,
+ repeatConfig: { pattern?: string; every?: number },
+ jobTemplate?: {
+ name?: TQueueJobTypes[T]["name"];
+ data?: TQueueJobTypes[T]["payload"];
+ opts?: {
+ removeOnComplete?: boolean | { count: number };
+ removeOnFail?: boolean | { count: number };
+ delay?: number;
+ };
+ }
+ ) => Promise<void>;
+ removeJobScheduler: <T extends QueueName>(name: T, schedulerId: string) => Promise<void>;
+ getJobSchedulers: (name: QueueName, start?: number, end?: number) => Promise<JobSchedulerJson[]>;
};
export const queueServiceFactory = (
@@ -628,15 +649,11 @@ export const queueServiceFactory = (
): TQueueServiceFactory => {
const isClusterMode = Boolean(redisCfg?.REDIS_CLUSTER_HOSTS);
const connection = buildRedisFromConfig(redisCfg);
- const queueContainer = {} as Record<
- QueueName,
- Queue<TQueueJobTypes[QueueName]["payload"], void, TQueueJobTypes[QueueName]["name"]>
- >;
+ const queueContainer: Partial<Record<QueueName, Queue<TQueueJobTypes[QueueName]["payload"], void, string>>> = {};
- const workerContainer = {} as Record<
- QueueName,
- Worker<TQueueJobTypes[QueueName]["payload"], void, TQueueJobTypes[QueueName]["name"]>
- >;
+ const workerContainer: Partial<
+ Record<QueueName, Worker<TQueueJobTypes[QueueName]["payload"], void, TQueueJobTypes[QueueName]["name"]>>
+ > = {};
const persistantQueues = new Set<QueueName>();
@@ -926,16 +943,15 @@ export const queueServiceFactory = (
removeOnFail: true
});
- // Schedule reconciliation job (runs every 2 minute)
- await queueContainer[QueueName.QueueInternalReconciliation].add(QueueJobs.QueueReconciliation, undefined, {
- jobId: "queue-reconciliation-cron",
- repeat: {
- pattern: "*/2 * * * *",
- key: "queue-reconciliation-cron"
- },
- removeOnComplete: true,
- removeOnFail: true
- });
+ // Schedule reconciliation job (runs every 2 minutes)
+ await queueContainer[QueueName.QueueInternalReconciliation]?.upsertJobScheduler(
+ "queue-reconciliation-cron",
+ { pattern: "*/2 * * * *", utc: true },
+ {
+ name: QueueJobs.QueueReconciliation,
+ opts: { removeOnComplete: true, removeOnFail: true }
+ }
+ );
logger.info("Internal queue recovery and reconciliation workers started");
}
@@ -1001,7 +1017,7 @@ export const queueServiceFactory = (
persistentQueueConfigs.set(name, persistenceConfig);
persistantQueues.add(name);
- workerContainer[name].on("active", (job) => {
+ workerContainer[name]?.on("active", (job) => {
if (job.id) {
void queueJobsDAL
.update(
@@ -1018,7 +1034,7 @@ export const queueServiceFactory = (
}
});
- workerContainer[name].on("completed", (job) => {
+ workerContainer[name]?.on("completed", (job) => {
if (job.id) {
void queueJobsDAL
.update(
@@ -1034,7 +1050,7 @@ export const queueServiceFactory = (
}
});
- workerContainer[name].on("failed", (job, error) => {
+ workerContainer[name]?.on("failed", (job, error) => {
if (job?.id) {
void queueJobsDAL.updateJobFailure(name, job.id, error.message).catch((err) => {
logger.error(err, "Failed to update queue job status failed");
@@ -1051,7 +1067,7 @@ export const queueServiceFactory = (
}
const worker = workerContainer[name];
- worker.on(event, listener);
+ worker?.on(event, listener);
};
const queue: TQueueServiceFactory["queue"] = async (name, job, data, opts) => {
@@ -1082,12 +1098,12 @@ export const queueServiceFactory = (
tx
);
// if this fails transaction rollback happens
- await q.add(job, data, finalOptions);
+ await q?.add(job, data, finalOptions);
});
return;
}
- await q.add(job, data, finalOptions);
+ await q?.add(job, data, finalOptions);
};
const stopRepeatableJob: TQueueServiceFactory["stopRepeatableJob"] = async (name, job, repeatOpt, jobId) => {
@@ -1113,21 +1129,29 @@ export const queueServiceFactory = (
const stopRepeatableJobByJobId: TQueueServiceFactory["stopRepeatableJobByJobId"] = async (name, jobId) => {
const q = queueContainer[name];
+ if (!q) {
+ return true;
+ }
+
const job = await q.getJob(jobId);
- if (!job) return true;
- if (!job.repeatJobKey) return true;
+ if (!job?.repeatJobKey) {
+ return true;
+ }
await job.remove();
return q.removeRepeatableByKey(job.repeatJobKey);
};
const stopRepeatableJobByKey: TQueueServiceFactory["stopRepeatableJobByKey"] = async (name, repeatJobKey) => {
const q = queueContainer[name];
- return q.removeRepeatableByKey(repeatJobKey);
+ if (!q) {
+ return true;
+ }
+ return q?.removeRepeatableByKey(repeatJobKey);
};
const stopJobById: TQueueServiceFactory["stopJobById"] = async (name, jobId) => {
const q = queueContainer[name];
- const job = await q.getJob(jobId);
+ const job = await q?.getJob(jobId);
const isPersistantQueue = persistantQueues.has(name);
if (isPersistantQueue) {
@@ -1139,16 +1163,14 @@ export const queueServiceFactory = (
const clearQueue: TQueueServiceFactory["clearQueue"] = async (name) => {
const q = queueContainer[name];
- await q.drain();
+ await q?.drain();
};
const shutdown: TQueueServiceFactory["shutdown"] = async () => {
- // Stop internal queue repeatable jobs
+ // Stop internal queue scheduler jobs
try {
const reconciliationQueue = queueContainer[QueueName.QueueInternalReconciliation];
- if (reconciliationQueue) {
- await reconciliationQueue.removeRepeatableByKey("queue-reconciliation-cron");
- }
+ await reconciliationQueue?.removeJobScheduler("queue-reconciliation-cron");
} catch {
// Ignore errors during shutdown
}
@@ -1166,6 +1188,44 @@ export const queueServiceFactory = (
await queueJobsDAL.update({ queueName, jobId }, { lastHeartBeat: new Date() });
};
+ const upsertJobScheduler: TQueueServiceFactory["upsertJobScheduler"] = async (
+ name,
+ schedulerId,
+ repeatConfig,
+ jobTemplate
+ ) => {
+ const q = queueContainer[name];
+ if (!q) throw new Error(`Queue '${name}' not initialized`);
+
+ await q.upsertJobScheduler(
+ schedulerId,
+ { ...repeatConfig, utc: true },
+ {
+ name: jobTemplate?.name ?? schedulerId,
+ data: jobTemplate?.data,
+ opts: {
+ removeOnComplete: true,
+ removeOnFail: true,
+ ...jobTemplate?.opts
+ }
+ }
+ );
+ };
+
+ const removeJobScheduler: TQueueServiceFactory["removeJobScheduler"] = async (name, schedulerId) => {
+ const q = queueContainer[name];
+ if (!q) throw new Error(`Queue '${name}' not initialized`);
+
+ await q.removeJobScheduler(schedulerId);
+ };
+
+ const getJobSchedulers: TQueueServiceFactory["getJobSchedulers"] = async (name, startOffset, endOffset) => {
+ const q = queueContainer[name];
+ if (!q) throw new Error(`Queue '${name}' not initialized`);
+
+ return q.getJobSchedulers(startOffset, endOffset);
+ };
+
return {
initialize,
start,
@@ -1179,6 +1239,9 @@ export const queueServiceFactory = (
stopJobById,
getRepeatableJobs,
getDelayedJobs,
- updateJobHeartbeat
+ updateJobHeartbeat,
+ upsertJobScheduler,
+ removeJobScheduler,
+ getJobSchedulers
};
};
diff --git a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-queue.ts b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-queue.ts
index c303ed5490..1ced59cadd 100644
--- a/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-queue.ts
+++ b/backend/src/services/app-connection/credential-rotation/app-connection-credential-rotation-queue.ts
@@ -216,16 +216,10 @@ export const appConnectionCredentialRotationQueueFactory = async ({
});
// Schedule the cron job
- await queueService.queue(
+ await queueService.upsertJobScheduler(
QueueName.AppConnectionCredentialRotation,
- QueueJobs.AppConnectionCredentialRotationQueueRotations,
- undefined,
- {
- jobId: "app-connection-credential-rotation-cron",
- repeat: {
- pattern: appCfg.isRotationDevelopmentMode ? "* * * * *" : "0 0 * * *",
- key: "app-connection-credential-rotation-cron"
- }
- }
+ "app-connection-credential-rotation-cron",
+ { pattern: appCfg.isRotationDevelopmentMode ? "* * * * *" : "0 0 * * *" },
+ { name: QueueJobs.AppConnectionCredentialRotationQueueRotations }
);
};
diff --git a/backend/src/services/certificate-authority/certificate-authority-queue.ts b/backend/src/services/certificate-authority/certificate-authority-queue.ts
index 26343d74fe..94a03f2a35 100644
--- a/backend/src/services/certificate-authority/certificate-authority-queue.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-queue.ts
@@ -112,19 +112,12 @@ export const certificateAuthorityQueueFactory = ({
// Daily at midnight UTC; only CRLs expiring before next run are rebuilt
const cronPattern = appCfg.NODE_ENV === "development" ? "*/5 * * * *" : "0 0 * * *";
- // clear previous repeatable job
- await queueService.stopRepeatableJob(
+ await queueService.upsertJobScheduler(
QueueName.CaCrlRotation,
QueueJobs.CaCrlRotation,
- { pattern: cronPattern, utc: true },
- QueueJobs.CaCrlRotation
+ { pattern: cronPattern },
+ { name: QueueJobs.CaCrlRotation, opts: { delay: 5000 } }
);
-
- await queueService.queue(QueueName.CaCrlRotation, QueueJobs.CaCrlRotation, undefined, {
- delay: 5000,
- jobId: QueueJobs.CaCrlRotation,
- repeat: { pattern: cronPattern, utc: true, key: QueueJobs.CaCrlRotation }
- });
};
const orderCertificateForSubscriber = async ({ subscriberId, caType }: TOrderCertificateForSubscriberDTO) => {
diff --git a/backend/src/services/certificate-v3/certificate-v3-queue.ts b/backend/src/services/certificate-v3/certificate-v3-queue.ts
index 3179650b2b..e29fb1eaa5 100644
--- a/backend/src/services/certificate-v3/certificate-v3-queue.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-queue.ts
@@ -29,13 +29,6 @@ export const certificateV3QueueServiceFactory = ({
return;
}
- await queueService.stopRepeatableJob(
- QueueName.CertificateV3AutoRenewal,
- QueueJobs.CertificateV3DailyAutoRenewal,
- { pattern: CERTIFICATE_RENEWAL_CONFIG.DAILY_CRON_SCHEDULE, utc: true },
- QueueName.CertificateV3AutoRenewal
- );
-
queueService.start(QueueName.CertificateV3AutoRenewal, async () => {
try {
logger.info(`${QueueJobs.CertificateV3DailyAutoRenewal}: queue task started`);
@@ -139,13 +132,12 @@ export const certificateV3QueueServiceFactory = ({
}
});
- await queueService.queue(QueueName.CertificateV3AutoRenewal, QueueJobs.CertificateV3DailyAutoRenewal, undefined, {
- jobId: QueueJobs.CertificateV3DailyAutoRenewal,
- repeat: {
- pattern: CERTIFICATE_RENEWAL_CONFIG.DAILY_CRON_SCHEDULE,
- key: QueueJobs.CertificateV3DailyAutoRenewal
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.CertificateV3AutoRenewal,
+ QueueJobs.CertificateV3DailyAutoRenewal,
+ { pattern: CERTIFICATE_RENEWAL_CONFIG.DAILY_CRON_SCHEDULE },
+ { name: QueueJobs.CertificateV3DailyAutoRenewal }
+ );
};
return {
diff --git a/backend/src/services/health-alert/health-alert-queue.ts b/backend/src/services/health-alert/health-alert-queue.ts
index db2c525458..9ea92cd57d 100644
--- a/backend/src/services/health-alert/health-alert-queue.ts
+++ b/backend/src/services/health-alert/health-alert-queue.ts
@@ -24,13 +24,6 @@ export const healthAlertServiceFactory = ({
return;
}
- await queueService.stopRepeatableJob(
- QueueName.HealthAlert,
- QueueJobs.HealthAlert,
- { pattern: "*/5 * * * *", utc: true },
- QueueName.HealthAlert // job id
- );
-
queueService.start(QueueName.HealthAlert, async () => {
try {
logger.info(`${QueueName.HealthAlert}: health check alert task started`);
@@ -43,13 +36,12 @@ export const healthAlertServiceFactory = ({
}
});
- await queueService.queue(QueueName.HealthAlert, QueueJobs.HealthAlert, undefined, {
- jobId: QueueJobs.HealthAlert,
- repeat: {
- pattern: "*/5 * * * *",
- key: QueueJobs.HealthAlert
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.HealthAlert,
+ QueueJobs.HealthAlert,
+ { pattern: "*/5 * * * *" },
+ { name: QueueJobs.HealthAlert }
+ );
};
return {
diff --git a/backend/src/services/pam-account-rotation/pam-account-rotation-queue.ts b/backend/src/services/pam-account-rotation/pam-account-rotation-queue.ts
index 419774280a..4ffb5d349f 100644
--- a/backend/src/services/pam-account-rotation/pam-account-rotation-queue.ts
+++ b/backend/src/services/pam-account-rotation/pam-account-rotation-queue.ts
@@ -21,13 +21,6 @@ export const pamAccountRotationServiceFactory = ({
return;
}
- await queueService.stopRepeatableJob(
- QueueName.PamAccountRotation,
- QueueJobs.PamAccountRotation,
- { pattern: "0 * * * *", utc: true },
- QueueName.PamAccountRotation // job id
- );
-
queueService.start(QueueName.PamAccountRotation, async () => {
try {
logger.info(`${QueueName.PamAccountRotation}: pam account rotation task started`);
@@ -39,13 +32,12 @@ export const pamAccountRotationServiceFactory = ({
}
});
- await queueService.queue(QueueName.PamAccountRotation, QueueJobs.PamAccountRotation, undefined, {
- jobId: QueueJobs.PamAccountRotation,
- repeat: {
- pattern: "0 * * * *",
- key: QueueJobs.PamAccountRotation
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.PamAccountRotation,
+ QueueJobs.PamAccountRotation,
+ { pattern: "0 * * * *" },
+ { name: QueueJobs.PamAccountRotation }
+ );
};
return {
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
index 55067ee3ec..82dd4b01f1 100644
--- a/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-queue.ts
@@ -210,13 +210,12 @@ export const pkiAlertV2QueueServiceFactory = ({
}
});
- await queueService.queue(QueueName.DailyPkiAlertV2Processing, QueueJobs.DailyPkiAlertV2Processing, undefined, {
- jobId: QueueJobs.DailyPkiAlertV2Processing,
- repeat: {
- pattern: "0 0 * * *",
- key: QueueJobs.DailyPkiAlertV2Processing
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.DailyPkiAlertV2Processing,
+ QueueJobs.DailyPkiAlertV2Processing,
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.DailyPkiAlertV2Processing }
+ );
};
return {
diff --git a/backend/src/services/pki-alert/expiring-pki-item-alert-queue.ts b/backend/src/services/pki-alert/expiring-pki-item-alert-queue.ts
index c3eebd6c39..2a0aa29c97 100644
--- a/backend/src/services/pki-alert/expiring-pki-item-alert-queue.ts
+++ b/backend/src/services/pki-alert/expiring-pki-item-alert-queue.ts
@@ -23,19 +23,12 @@ export const dailyExpiringPkiItemAlertQueueServiceFactory = ({
// we do a repeat cron job in utc timezone at 12 Midnight each day
const startSendingAlerts = async () => {
- // clear previous job
- await queueService.stopRepeatableJob(
+ await queueService.upsertJobScheduler(
QueueName.DailyExpiringPkiItemAlert,
- QueueJobs.DailyExpiringPkiItemAlert,
- { pattern: "0 0 * * *", utc: true },
- QueueName.DailyExpiringPkiItemAlert // just a job id
+ QueueName.DailyExpiringPkiItemAlert,
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.DailyExpiringPkiItemAlert, opts: { delay: 5000 } }
);
-
- await queueService.queue(QueueName.DailyExpiringPkiItemAlert, QueueJobs.DailyExpiringPkiItemAlert, undefined, {
- delay: 5000,
- jobId: QueueName.DailyExpiringPkiItemAlert,
- repeat: { pattern: "0 0 * * *", utc: true, key: QueueName.DailyExpiringPkiItemAlert }
- });
};
queueService.listen(QueueName.DailyExpiringPkiItemAlert, "failed", (_, err) => {
diff --git a/backend/src/services/pki-subscriber/pki-subscriber-queue.ts b/backend/src/services/pki-subscriber/pki-subscriber-queue.ts
index 8c8ab27edd..bc84c547be 100644
--- a/backend/src/services/pki-subscriber/pki-subscriber-queue.ts
+++ b/backend/src/services/pki-subscriber/pki-subscriber-queue.ts
@@ -159,21 +159,12 @@ export const pkiSubscriberQueueServiceFactory = ({
// we do a repeat cron job in utc timezone at 12 Midnight each day
const startDailyAutoRenewalJob = async () => {
- // clear previous job
- await queueService.stopRepeatableJob(
+ await queueService.upsertJobScheduler(
QueueName.PkiSubscriber,
- QueueJobs.PkiSubscriberDailyAutoRenewal,
- { pattern: "0 0 * * *", utc: true },
- // { pattern: "*/30 * * * * *", utc: true } // for testing
- QueueName.PkiSubscriber // just a job id
+ QueueName.PkiSubscriber,
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.PkiSubscriberDailyAutoRenewal, opts: { delay: 5000 } }
);
-
- await queueService.queue(QueueName.PkiSubscriber, QueueJobs.PkiSubscriberDailyAutoRenewal, undefined, {
- delay: 5000,
- jobId: QueueName.PkiSubscriber,
- // { pattern: "*/30 * * * * *", utc: true } // for testing
- repeat: { pattern: "0 0 * * *", utc: true, key: QueueName.PkiSubscriber }
- });
};
queueService.listen(QueueName.PkiSubscriber, "failed", (_, err) => {
diff --git a/backend/src/services/pki-sync/pki-sync-cleanup-queue.ts b/backend/src/services/pki-sync/pki-sync-cleanup-queue.ts
index 2cc28449a6..5659644b88 100644
--- a/backend/src/services/pki-sync/pki-sync-cleanup-queue.ts
+++ b/backend/src/services/pki-sync/pki-sync-cleanup-queue.ts
@@ -58,13 +58,6 @@ export const pkiSyncCleanupQueueServiceFactory = ({
return;
}
- await queueService.stopRepeatableJob(
- QueueName.PkiSyncCleanup,
- QueueJobs.PkiSyncCleanup,
- { pattern: "0 0 * * *", utc: true },
- QueueName.PkiSyncCleanup // just a job id
- );
-
queueService.start(QueueName.PkiSyncCleanup, async () => {
try {
logger.info(`${QueueName.PkiSyncCleanup}: queue task started`);
@@ -76,13 +69,12 @@ export const pkiSyncCleanupQueueServiceFactory = ({
}
});
- await queueService.queue(QueueName.PkiSyncCleanup, QueueJobs.PkiSyncCleanup, undefined, {
- jobId: QueueJobs.PkiSyncCleanup,
- repeat: {
- pattern: "0 0 * * *",
- key: QueueJobs.PkiSyncCleanup
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.PkiSyncCleanup,
+ QueueJobs.PkiSyncCleanup,
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.PkiSyncCleanup }
+ );
};
return {
diff --git a/backend/src/services/reminder/reminder-queue.ts b/backend/src/services/reminder/reminder-queue.ts
index cb46378da7..f57744933d 100644
--- a/backend/src/services/reminder/reminder-queue.ts
+++ b/backend/src/services/reminder/reminder-queue.ts
@@ -149,19 +149,12 @@ export const dailyReminderQueueServiceFactory = ({
// we do a repeat cron job in utc timezone at 12 Midnight each day
const startDailyRemindersJob = async () => {
- // clear previous job
- await queueService.stopRepeatableJob(
+ await queueService.upsertJobScheduler(
QueueName.DailyReminders,
QueueJobs.DailyReminders,
- { pattern: "0 0 * * *", utc: true },
- QueueName.DailyReminders // just a job id
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.DailyReminders, opts: { delay: 5000 } }
);
-
- await queueService.queue(QueueName.DailyReminders, QueueJobs.DailyReminders, undefined, {
- delay: 5000,
- jobId: QueueName.DailyReminders,
- repeat: { pattern: "0 0 * * *", utc: true, key: QueueJobs.DailyReminders }
- });
};
// TODO: remove once all the old reminders in queues are migrated
diff --git a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
index 21fdb25c6b..64aa139107 100644
--- a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
+++ b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
@@ -102,22 +102,14 @@ export const dailyResourceCleanUpQueueServiceFactory = ({
}
});
- await queueService.queue(QueueName.DailyResourceCleanUp, QueueJobs.DailyResourceCleanUp, undefined, {
- jobId: QueueJobs.DailyResourceCleanUp,
- repeat: {
- pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 0 * * *",
- key: QueueJobs.DailyResourceCleanUp
- }
- });
-
- // Hourly cleanup routine
- await queueService.stopRepeatableJob(
- QueueName.FrequentResourceCleanUp,
- QueueJobs.FrequentResourceCleanUp,
- { pattern: "0 * * * *", utc: true },
- QueueName.FrequentResourceCleanUp // just a job id
+ await queueService.upsertJobScheduler(
+ QueueName.DailyResourceCleanUp,
+ QueueJobs.DailyResourceCleanUp,
+ { pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 0 * * *" },
+ { name: QueueJobs.DailyResourceCleanUp }
);
+ // Hourly cleanup routine
queueService.start(QueueName.FrequentResourceCleanUp, async () => {
try {
logger.info(`${QueueName.FrequentResourceCleanUp}: queue task started`);
@@ -129,13 +121,12 @@ export const dailyResourceCleanUpQueueServiceFactory = ({
}
});
- await queueService.queue(QueueName.FrequentResourceCleanUp, QueueJobs.FrequentResourceCleanUp, undefined, {
- jobId: QueueJobs.FrequentResourceCleanUp,
- repeat: {
- pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 * * * *",
- key: QueueJobs.FrequentResourceCleanUp
- }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.FrequentResourceCleanUp,
+ QueueJobs.FrequentResourceCleanUp,
+ { pattern: appCfg.isDailyResourceCleanUpDevelopmentMode ? "*/5 * * * *" : "0 * * * *" },
+ { name: QueueJobs.FrequentResourceCleanUp }
+ );
};
return {
diff --git a/backend/src/services/telemetry/telemetry-queue.ts b/backend/src/services/telemetry/telemetry-queue.ts
index 35b855795a..333ef3f64b 100644
--- a/backend/src/services/telemetry/telemetry-queue.ts
+++ b/backend/src/services/telemetry/telemetry-queue.ts
@@ -63,37 +63,25 @@ export const telemetryQueueServiceFactory = ({
const startTelemetryCheck = async () => {
// this is a fast way to check its cloud or not
if (appCfg.INFISICAL_CLOUD) return;
- // clear previous job
- await queueService.stopRepeatableJob(
- QueueName.TelemetryInstanceStats,
- QueueJobs.TelemetryInstanceStats,
- { pattern: "0 0 * * *", utc: true },
- QueueName.TelemetryInstanceStats // just a job id
- );
-
if (postHog) {
- await queueService.queue(QueueName.TelemetryInstanceStats, QueueJobs.TelemetryInstanceStats, undefined, {
- jobId: QueueName.TelemetryInstanceStats,
- repeat: { pattern: "0 0 * * *", utc: true, key: QueueName.TelemetryInstanceStats }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.TelemetryInstanceStats,
+ QueueName.TelemetryInstanceStats,
+ { pattern: "0 0 * * *" },
+ { name: QueueJobs.TelemetryInstanceStats }
+ );
}
};
const startAggregatedEventsJob = async () => {
- // clear previous aggregated events job
- await queueService.stopRepeatableJob(
- QueueName.TelemetryAggregatedEvents,
- QueueJobs.TelemetryAggregatedEvents,
- { pattern: "*/5 * * * *", utc: true },
- QueueName.TelemetryAggregatedEvents // just a job id
- );
-
if (postHog) {
// Start aggregated events job (runs every five minutes)
- await queueService.queue(QueueName.TelemetryAggregatedEvents, QueueJobs.TelemetryAggregatedEvents, undefined, {
- jobId: QueueName.TelemetryAggregatedEvents,
- repeat: { pattern: "*/5 * * * *", utc: true, key: QueueName.TelemetryAggregatedEvents }
- });
+ await queueService.upsertJobScheduler(
+ QueueName.TelemetryAggregatedEvents,
+ QueueName.TelemetryAggregatedEvents,
+ { pattern: "*/5 * * * *" },
+ { name: QueueJobs.TelemetryAggregatedEvents }
+ );
}
};