mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Add minor improvements to notifyExpiredTokens
This commit is contained in:
@@ -77,7 +77,7 @@ export const dailyResourceCleanUpQueueServiceFactory = ({
|
||||
await queueService.queue(QueueName.DailyResourceCleanUp, QueueJobs.DailyResourceCleanUp, undefined, {
|
||||
delay: 5000,
|
||||
jobId: QueueName.DailyResourceCleanUp,
|
||||
repeat: { pattern: "0 0 * * *", utc: true }
|
||||
repeat: { pattern: "* * * * *", utc: true }
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ export const serviceTokenDALFactory = (db: TDbClient) => {
|
||||
.whereRaw(
|
||||
`${TableName.ServiceToken}."expiresAt" < NOW() AND ${TableName.ServiceToken}."notificationSent" = false`
|
||||
)
|
||||
.whereNotNull(`${TableName.Users}.email`)
|
||||
.select(`${TableName.ServiceToken}.name`)
|
||||
.select(`${TableName.ServiceToken}.id`)
|
||||
.select(`${TableName.Project}.name as projectName`)
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
TGetServiceTokenInfoDTO,
|
||||
TProjectServiceTokensDTO
|
||||
} from "./service-token-types";
|
||||
import { logger } from "@app/lib/logger";
|
||||
|
||||
type TServiceTokenServiceFactoryDep = {
|
||||
serviceTokenDAL: TServiceTokenDALFactory;
|
||||
@@ -196,8 +197,8 @@ export const serviceTokenServiceFactory = ({
|
||||
|
||||
await Promise.all(
|
||||
expiredTokens.map(async (token) => {
|
||||
await smtpService
|
||||
.sendMail({
|
||||
try {
|
||||
await smtpService.sendMail({
|
||||
recipients: [token.createdByEmail],
|
||||
subjectLine: "Service Token Expired",
|
||||
template: SmtpTemplates.ServiceTokenExpired,
|
||||
@@ -206,10 +207,11 @@ export const serviceTokenServiceFactory = ({
|
||||
projectName: token.projectName,
|
||||
url: `${appCfg.SITE_URL}/secret-manager/${token.projectId}/access-management?selectedTab=service-tokens`
|
||||
}
|
||||
})
|
||||
.then(async () => {
|
||||
await serviceTokenDAL.update({ id: token.id }, { notificationSent: true });
|
||||
});
|
||||
await serviceTokenDAL.update({ id: token.id }, { notificationSent: true });
|
||||
} catch (error) {
|
||||
logger.error(error, `Failed to send expiration notification for token ${token.id}:`);
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user