diff --git a/packages/server/api/src/app/ee/authentication/saml-authn/authn-sso-saml-module.ts b/packages/server/api/src/app/ee/authentication/saml-authn/authn-sso-saml-module.ts index ce391fe3303..cd8b06d446b 100644 --- a/packages/server/api/src/app/ee/authentication/saml-authn/authn-sso-saml-module.ts +++ b/packages/server/api/src/app/ee/authentication/saml-authn/authn-sso-saml-module.ts @@ -1,22 +1,12 @@ import { FastifyPluginAsyncZod } from 'fastify-type-provider-zod' -import { SystemJobName } from '../../../helper/system-jobs/common' -import { systemJobHandlers } from '../../../helper/system-jobs/job-handlers' -import { systemJobsSchedule } from '../../../helper/system-jobs/system-job' +import cron from 'node-cron' +import { rejectedPromiseHandler } from '../../../helper/promise-handler' import { authnSsoSamlController } from './authn-sso-saml-controller' import { authnSsoSamlService } from './authn-sso-saml-service' export const authnSsoSamlModule: FastifyPluginAsyncZod = async (app) => { - systemJobHandlers.registerJobHandler(SystemJobName.EXPIRE_PENDING_SSO_DOMAINS, async () => authnSsoSamlService(app.log).expirePendingSsoDomains()) - void systemJobsSchedule(app.log).upsertJob({ - job: { - name: SystemJobName.EXPIRE_PENDING_SSO_DOMAINS, - data: {}, - jobId: SystemJobName.EXPIRE_PENDING_SSO_DOMAINS, - }, - schedule: { - type: 'repeated', - cron: '0 * * * *', - }, + cron.schedule('0 * * * *', () => { + rejectedPromiseHandler(authnSsoSamlService(app.log).expirePendingSsoDomains(), app.log) }) await app.register(authnSsoSamlController, { prefix: '/v1/authn/saml' }) } diff --git a/packages/server/api/src/app/helper/system-jobs/common.ts b/packages/server/api/src/app/helper/system-jobs/common.ts index 7296ceb8819..fde02d92ff2 100644 --- a/packages/server/api/src/app/helper/system-jobs/common.ts +++ b/packages/server/api/src/app/helper/system-jobs/common.ts @@ -13,7 +13,6 @@ export enum SystemJobName { HARD_DELETE_PROJECT = 'hard-delete-project', HARD_DELETE_PLATFORM = 'hard-delete-platform', RESUME_DELAY_WAITPOINT = 'resume-delay-waitpoint', - EXPIRE_PENDING_SSO_DOMAINS = 'expire-pending-sso-domains', } type DeleteFlowDurableSystemJobData = { @@ -55,7 +54,6 @@ type SystemJobDataMap = { [SystemJobName.HARD_DELETE_PROJECT]: HardDeleteProjectSystemJobData [SystemJobName.HARD_DELETE_PLATFORM]: HardDeletePlatformSystemJobData [SystemJobName.RESUME_DELAY_WAITPOINT]: ResumeDelayWaitpointSystemJobData - [SystemJobName.EXPIRE_PENDING_SSO_DOMAINS]: Record } export type SystemJobData = T extends SystemJobName ? SystemJobDataMap[T] : never diff --git a/packages/server/api/src/app/helper/system-jobs/system-job.ts b/packages/server/api/src/app/helper/system-jobs/system-job.ts index aca42666c9b..4fc6b3b0aaa 100644 --- a/packages/server/api/src/app/helper/system-jobs/system-job.ts +++ b/packages/server/api/src/app/helper/system-jobs/system-job.ts @@ -114,6 +114,7 @@ async function removeDeprecatedJobs(): Promise { 'seven-days-in-trial', 'issue-reminder', 'update-flow-status', + 'expire-pending-sso-domains', ] const allSystemJobs = await systemJobsQueue.getJobSchedulers() const knownJobNames = Object.values(SystemJobName) as string[]