From d30f3bf1f8395d24ee63a8e846283d5be1d0dbfd Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 26 Oct 2024 00:55:07 +0530 Subject: [PATCH] feat: update last run and next run values --- server/src/worker.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/src/worker.ts b/server/src/worker.ts index 1a138d56..96fded7b 100644 --- a/server/src/worker.ts +++ b/server/src/worker.ts @@ -32,6 +32,23 @@ const worker = new Worker('workflow', async job => { worker.on('completed', async (job: any) => { logger.log(`info`, `Job ${job.id} completed for ${job.data.runId}`); + const robot = await Robot.findOne({ where: { 'recording_meta.id': job.data.id } }); + if (robot) { + // Update `lastRunAt` to the current time + const lastRunAt = new Date(); + + // Compute the next run date + const nextRunAt = computeNextRun(robot.schedule.cronExpression, robot.schedule.timezone); + + await robot.update({ + schedule: { + ...robot.schedule, + lastRunAt, + nextRunAt, + }, + }); + } +}); }); worker.on('failed', async (job: any, err) => {