From 4ac37e387ab08b045e4923de5f7d4552e3287a54 Mon Sep 17 00:00:00 2001 From: anoopkarnik Date: Wed, 21 Aug 2024 12:05:30 +0530 Subject: [PATCH] Added scheduler correction with timezone --- apps/dashboard-app/routes.ts | 2 +- apps/scheduler/src/index.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/dashboard-app/routes.ts b/apps/dashboard-app/routes.ts index 2e63efe..5740e0a 100644 --- a/apps/dashboard-app/routes.ts +++ b/apps/dashboard-app/routes.ts @@ -1,6 +1,6 @@ export const publicRoutes = [ - "/landing","/auth/new-verification",'/api' + "/landing","/auth/new-verification",'/api/hooks/catch' ] export const authRoutes =[ diff --git a/apps/scheduler/src/index.ts b/apps/scheduler/src/index.ts index 296af79..7e562b0 100644 --- a/apps/scheduler/src/index.ts +++ b/apps/scheduler/src/index.ts @@ -34,20 +34,20 @@ async function main() { if (workflow.trigger?.type.name === 'Cron'){ logger.info(`Processing cron workflow ${workflow.id}`); const metadata:any = workflow.trigger?.metadata; - const startDate = new Date(metadata?.startDate); - const now = new Date(); const timezone = metadata?.timezone; + const startDate = moment(metadata?.startDate).tz(timezone).toDate(); + const now = moment().tz(timezone).toDate(); const cronExpression = metadata?.cronExpression; let lastRun; if (workflow.lastRun){ - lastRun = new Date(workflow.lastRun); + lastRun = moment(workflow.lastRun).tz(timezone).toDate(); } else{ - lastRun = new Date(metadata.startDate); + lastRun = moment(metadata.startDate).tz(timezone).toDate(); } const interval = cronParser.parseExpression(cronExpression,{currentDate: lastRun, tz: timezone}); - let nextRun:Date = interval.next().toDate (); - const local_time = moment(new Date()) + let nextRun:Date = interval.next().toDate(); + const local_time = moment().tz(timezone); let eventMetadata = { trigger: { result:{