Skip to content

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

Add minor improvements to notifyExpiredTokens

carlosmonastyrski86d7fca8fbfc
diff --git a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
index edd6847830..5adb91801c 100644
--- a/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
+++ b/backend/src/services/resource-cleanup/resource-cleanup-queue.ts
@@ -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 }
});
};
diff --git a/backend/src/services/service-token/service-token-dal.ts b/backend/src/services/service-token/service-token-dal.ts
index d9125c1234..188cd86cd7 100644
--- a/backend/src/services/service-token/service-token-dal.ts
+++ b/backend/src/services/service-token/service-token-dal.ts
@@ -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`)
diff --git a/backend/src/services/service-token/service-token-service.ts b/backend/src/services/service-token/service-token-service.ts
index dd2f834bb6..db44e6272b 100644
--- a/backend/src/services/service-token/service-token-service.ts
+++ b/backend/src/services/service-token/service-token-service.ts
@@ -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}:`);
+ }
})
);
};