mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 02:28:39 +00:00
Use PG instead of bullMQ on the new certificates renew queue
This commit is contained in:
@@ -2339,7 +2339,7 @@ export const registerRoutes = async (
|
||||
await dailyReminderQueueService.startSecretReminderMigrationJob();
|
||||
await dailyExpiringPkiItemAlert.startSendingAlerts();
|
||||
await pkiSubscriberQueue.startDailyAutoRenewalJob();
|
||||
await certificateV3Queue.startDailyAutoRenewalJob();
|
||||
await certificateV3Queue.init();
|
||||
await kmsService.startService(hsmStatus);
|
||||
await microsoftTeamsService.start();
|
||||
await dynamicSecretQueueService.init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
|
||||
import { getConfig } from "@app/lib/config/env";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||
|
||||
@@ -21,8 +22,24 @@ export const certificateV3QueueServiceFactory = ({
|
||||
certificateV3Service,
|
||||
auditLogService
|
||||
}: TCertificateV3QueueServiceFactoryDep) => {
|
||||
queueService.start(QueueName.CertificateV3AutoRenewal, async (job) => {
|
||||
if (job.name === QueueJobs.CertificateV3DailyAutoRenewal) {
|
||||
const appCfg = getConfig();
|
||||
|
||||
const init = async () => {
|
||||
if (appCfg.isSecondaryInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
await queueService.stopRepeatableJob(
|
||||
QueueName.CertificateV3AutoRenewal,
|
||||
QueueJobs.CertificateV3DailyAutoRenewal,
|
||||
{ pattern: CERTIFICATE_RENEWAL_CONFIG.DAILY_CRON_SCHEDULE, utc: true },
|
||||
QueueName.CertificateV3AutoRenewal
|
||||
);
|
||||
|
||||
await queueService.startPg<QueueName.CertificateV3AutoRenewal>(
|
||||
QueueJobs.CertificateV3DailyAutoRenewal,
|
||||
async () => {
|
||||
try {
|
||||
logger.info(`${QueueJobs.CertificateV3DailyAutoRenewal}: queue task started`);
|
||||
|
||||
const { QUEUE_BATCH_SIZE } = CERTIFICATE_RENEWAL_CONFIG;
|
||||
@@ -118,33 +135,29 @@ export const certificateV3QueueServiceFactory = ({
|
||||
logger.info(
|
||||
`${QueueJobs.CertificateV3DailyAutoRenewal}: queue task completed. Renewed ${totalCertificatesRenewed} certificates out of ${totalCertificatesFound}`
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(error, `${QueueJobs.CertificateV3DailyAutoRenewal}: certificate renewal failed`);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
{
|
||||
batchSize: 1,
|
||||
workerCount: 1,
|
||||
pollingIntervalSeconds: 60
|
||||
}
|
||||
});
|
||||
|
||||
const startDailyAutoRenewalJob = async () => {
|
||||
const { DAILY_CRON_SCHEDULE, QUEUE_START_DELAY_MS } = CERTIFICATE_RENEWAL_CONFIG;
|
||||
|
||||
await queueService.stopRepeatableJob(
|
||||
QueueName.CertificateV3AutoRenewal,
|
||||
QueueJobs.CertificateV3DailyAutoRenewal,
|
||||
{ pattern: DAILY_CRON_SCHEDULE, utc: true },
|
||||
QueueName.CertificateV3AutoRenewal
|
||||
);
|
||||
|
||||
await queueService.queue(QueueName.CertificateV3AutoRenewal, QueueJobs.CertificateV3DailyAutoRenewal, undefined, {
|
||||
delay: QUEUE_START_DELAY_MS,
|
||||
jobId: QueueName.CertificateV3AutoRenewal,
|
||||
repeat: { pattern: DAILY_CRON_SCHEDULE, utc: true }
|
||||
});
|
||||
await queueService.schedulePg(
|
||||
QueueJobs.CertificateV3DailyAutoRenewal,
|
||||
CERTIFICATE_RENEWAL_CONFIG.DAILY_CRON_SCHEDULE,
|
||||
undefined,
|
||||
{ tz: "UTC" }
|
||||
);
|
||||
};
|
||||
|
||||
queueService.listen(QueueName.CertificateV3AutoRenewal, "failed", (_, err) => {
|
||||
logger.error(err, `${QueueName.CertificateV3AutoRenewal}: failed`);
|
||||
});
|
||||
|
||||
return {
|
||||
startDailyAutoRenewalJob
|
||||
init
|
||||
};
|
||||
};
|
||||
|
||||
export type TCertificateV3QueueFactory = ReturnType<typeof certificateV3QueueServiceFactory>;
|
||||
export type TCertificateV3QueueServiceFactory = ReturnType<typeof certificateV3QueueServiceFactory>;
|
||||
|
||||
Reference in New Issue
Block a user