From 5c86522e28dc0152d9e94875d05f053e9b27c062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Fri, 25 Oct 2024 13:54:51 -0700 Subject: [PATCH] fix: Tasker new Date is fixed to lambda lifetime (#17342) --- packages/features/tasker/repository.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/features/tasker/repository.ts b/packages/features/tasker/repository.ts index db8da19d36..6452200fec 100644 --- a/packages/features/tasker/repository.ts +++ b/packages/features/tasker/repository.ts @@ -18,7 +18,8 @@ const whereMaxAttemptsReached: Prisma.TaskWhereInput = { }, }; -const whereUpcomingTasks: Prisma.TaskWhereInput = { +/** This is a function to ensure new Date is always fresh */ +const makeWhereUpcomingTasks = (): Prisma.TaskWhereInput => ({ // Get only tasks that have not succeeded yet succeededAt: null, // Get only tasks that are scheduled to run now or in the past @@ -33,7 +34,7 @@ const whereUpcomingTasks: Prisma.TaskWhereInput = { _container: "Task", }, }, -}; +}); export class Task { static async create( @@ -55,9 +56,9 @@ export class Task { } static async getNextBatch() { - console.info("Getting next batch of tasks", whereUpcomingTasks); + console.info("Getting next batch of tasks", makeWhereUpcomingTasks()); return db.task.findMany({ - where: whereUpcomingTasks, + where: makeWhereUpcomingTasks(), orderBy: { scheduledAt: "asc", }, @@ -87,7 +88,7 @@ export class Task { static async countUpcoming() { return db.task.count({ - where: whereUpcomingTasks, + where: makeWhereUpcomingTasks(), }); }