Add minor improvements to notifyExpiredTokens

This commit is contained in:
carlosmonastyrski
2025-04-14 21:52:16 -03:00
parent cac4f30ca8
commit 86d7fca8fb
3 changed files with 9 additions and 6 deletions

View File

@@ -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 }
});
};

View File

@@ -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`)

View File

@@ -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}:`);
}
})
);
};