diff --git a/packages/features/tasker/internal-tasker.ts b/packages/features/tasker/internal-tasker.ts index 108c43247d..ffe65dc125 100644 --- a/packages/features/tasker/internal-tasker.ts +++ b/packages/features/tasker/internal-tasker.ts @@ -15,15 +15,20 @@ export class InternalTasker implements Tasker { }; async processQueue(): Promise { const tasks = await Task.getNextBatch(); + console.info(`Processing ${tasks.length} tasks`, tasks); + const tasksPromises = tasks.map(async (task) => { + console.info(`Processing task ${task.id}`, task); const taskHandlerGetter = tasksMap[task.type as keyof typeof tasksMap]; if (!taskHandlerGetter) throw new Error(`Task handler not found for type ${task.type}`); + const taskHandler = await taskHandlerGetter(); return taskHandler(task.payload) .then(async () => { await Task.succeed(task.id); }) .catch(async (error) => { + console.info(`Error processing task ${task.id}: ${error}`); await Task.retry(task.id, error instanceof Error ? error.message : "Unknown error"); }); }); diff --git a/packages/features/tasker/repository.ts b/packages/features/tasker/repository.ts index 687eaa29cf..db8da19d36 100644 --- a/packages/features/tasker/repository.ts +++ b/packages/features/tasker/repository.ts @@ -42,6 +42,7 @@ export class Task { options: { scheduledAt?: Date; maxAttempts?: number } = {} ) { const { scheduledAt, maxAttempts } = options; + console.info("Creating task", { type, payload, scheduledAt, maxAttempts }); const newTask = await db.task.create({ data: { payload, @@ -54,6 +55,7 @@ export class Task { } static async getNextBatch() { + console.info("Getting next batch of tasks", whereUpcomingTasks); return db.task.findMany({ where: whereUpcomingTasks, orderBy: { @@ -134,15 +136,16 @@ export class Task { } static async cleanup() { - return db.task.deleteMany({ - where: { - OR: [ - // Get tasks that have succeeded - whereSucceeded, - // Get tasks where maxAttemps has been reached - whereMaxAttemptsReached, - ], - }, - }); + // TODO: Uncomment this later + // return db.task.deleteMany({ + // where: { + // OR: [ + // // Get tasks that have succeeded + // whereSucceeded, + // // Get tasks where maxAttemps has been reached + // whereMaxAttemptsReached, + // ], + // }, + // }); } }