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