From 82118ea976fd048a507a301e19ea744010a0942f Mon Sep 17 00:00:00 2001 From: folland87 Date: Fri, 6 Dec 2024 17:07:40 +0100 Subject: [PATCH] fix dates --- src/jobs/sirene/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/jobs/sirene/index.js b/src/jobs/sirene/index.js index 6238d394..51c23599 100644 --- a/src/jobs/sirene/index.js +++ b/src/jobs/sirene/index.js @@ -9,10 +9,16 @@ import { getSiretStockFromPaysage } from "./get-stock"; export default async function monitorSiren(job) { const now = new Date(); - const lastSuccessfullExecution = db.collection("_jobs").find({ - name: SIREN_TASK_NAME, - "result.status": "success", - }); + const lastSuccessfullExecution = db + .collection("_jobs") + .find( + { + name: SIREN_TASK_NAME, + "result.status": "success", + }, + { sort: { lastFinishedAt: -1 } }, + ) + .toArray(); const from = lastSuccessfullExecution ? lastSuccessfullExecution.result?.lastExecution ?.toISOString()