fetchers-v3 WIP

This commit is contained in:
Vyacheslav Matyukhin 2022-06-03 16:54:45 +03:00
parent 571d968aab
commit 1ec6f34908
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -68,15 +68,39 @@ export const getRobot = <Context>(
async schedule({ url, context = {} }) { async schedule({ url, context = {} }) {
const now = new Date(); const now = new Date();
await prisma.robot.create({
data: { const oldJob = await prisma.robot.findFirst({
url, where: {
platform: platform.name, platform: platform.name,
created: now, url,
scheduled: now, completed: {
context, 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,
},
});
}
}, },
}; };
}; };