mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
Make PR review adjustments
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||
import { TPkiAlertServiceFactory } from "@app/services/pki-alert/pki-alert-service";
|
||||
|
||||
type TDailyExpiringPkiItemAlertQueueServiceFactoryDep = {
|
||||
queueService: TQueueServiceFactory;
|
||||
pkiAlertService: Pick<TPkiAlertServiceFactory, "sendPkiItemExpiryNotices">;
|
||||
};
|
||||
|
||||
export type TDailyExpiringPkiItemAlertQueueServiceFactory = ReturnType<
|
||||
typeof dailyExpiringPkiItemAlertQueueServiceFactory
|
||||
>;
|
||||
|
||||
export const dailyExpiringPkiItemAlertQueueServiceFactory = ({
|
||||
queueService,
|
||||
pkiAlertService
|
||||
}: TDailyExpiringPkiItemAlertQueueServiceFactoryDep) => {
|
||||
queueService.start(QueueName.DailyExpiringPkiItemAlert, async () => {
|
||||
logger.info(`${QueueName.DailyExpiringPkiItemAlert}: queue task started`);
|
||||
await pkiAlertService.sendPkiItemExpiryNotices();
|
||||
logger.info(`${QueueName.DailyExpiringPkiItemAlert}: queue task completed`);
|
||||
});
|
||||
|
||||
// we do a repeat cron job in utc timezone at 12 Midnight each day
|
||||
const startSendingAlerts = async () => {
|
||||
// clear previous job
|
||||
await queueService.stopRepeatableJob(
|
||||
QueueName.DailyExpiringPkiItemAlert,
|
||||
QueueJobs.DailyExpiringPkiItemAlert,
|
||||
{ pattern: "0 0 * * *", utc: true },
|
||||
QueueName.DailyExpiringPkiItemAlert // just a job id
|
||||
);
|
||||
|
||||
await queueService.queue(QueueName.DailyExpiringPkiItemAlert, QueueJobs.DailyExpiringPkiItemAlert, undefined, {
|
||||
delay: 5000,
|
||||
jobId: QueueName.DailyExpiringPkiItemAlert,
|
||||
repeat: { pattern: "0 0 * * *", utc: true }
|
||||
});
|
||||
};
|
||||
|
||||
queueService.listen(QueueName.DailyExpiringPkiItemAlert, "failed", (_, err) => {
|
||||
logger.error(err, `${QueueName.DailyExpiringPkiItemAlert}: Expiring PKI item alert failed`);
|
||||
});
|
||||
|
||||
return {
|
||||
startSendingAlerts
|
||||
};
|
||||
};
|
||||
@@ -12,8 +12,11 @@ import { TPkiAlertDALFactory } from "./pki-alert-dal";
|
||||
import { TCreateAlertDTO, TDeleteAlertDTO, TGetAlertByIdDTO, TUpdateAlertDTO } from "./pki-alert-types";
|
||||
|
||||
type TPkiAlertServiceFactoryDep = {
|
||||
pkiAlertDAL: TPkiAlertDALFactory;
|
||||
pkiCollectionDAL: TPkiCollectionDALFactory;
|
||||
pkiAlertDAL: Pick<
|
||||
TPkiAlertDALFactory,
|
||||
"create" | "findById" | "updateById" | "deleteById" | "getExpiringPkiCollectionItemsForAlerting"
|
||||
>;
|
||||
pkiCollectionDAL: Pick<TPkiCollectionDALFactory, "findById">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||
smtpService: Pick<TSmtpService, "sendMail">;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user