From 1ec6f349086bda511d2d7cb6db1480a9ca4ef5b9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Fri, 3 Jun 2022 16:54:45 +0300 Subject: [PATCH] fetchers-v3 WIP --- src/backend/robot/index.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/backend/robot/index.ts b/src/backend/robot/index.ts index 89369aa..98537e0 100644 --- a/src/backend/robot/index.ts +++ b/src/backend/robot/index.ts @@ -68,15 +68,39 @@ export const getRobot = ( async schedule({ url, context = {} }) { const now = new Date(); - await prisma.robot.create({ - data: { - url, + + const oldJob = await prisma.robot.findFirst({ + where: { platform: platform.name, - created: now, - scheduled: now, - context, + url, + completed: { + equals: null, + }, }, }); + + if (oldJob) { + await prisma.robot.update({ + where: { + id: oldJob.id, + }, + data: { + created: now, + scheduled: now, + context, + }, + }); + } else { + await prisma.robot.create({ + data: { + url, + platform: platform.name, + created: now, + scheduled: now, + context, + }, + }); + } }, }; };