From 280393b307a7230ef261c4baca75f742c7e5ecb8 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Fri, 11 Jul 2025 23:26:01 -0700 Subject: [PATCH] Moodle Chron wrapped in tryCatch --- apps/hub-server/modules/chron.ts | 80 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/apps/hub-server/modules/chron.ts b/apps/hub-server/modules/chron.ts index a833d265..3b8e4f2b 100644 --- a/apps/hub-server/modules/chron.ts +++ b/apps/hub-server/modules/chron.ts @@ -32,51 +32,55 @@ const syncMoodleIds = async () => { }; const updateParticipantMoodleResults = async () => { - const participantsMoodlePending = await prisma.participant.findMany({ - where: { - finisherMoodleCurseCompleted: false, - Event: { - finisherMoodleCourseId: { - not: null, + try { + const participantsMoodlePending = await prisma.participant.findMany({ + where: { + finisherMoodleCurseCompleted: false, + Event: { + finisherMoodleCourseId: { + not: null, + }, }, }, - }, - include: { - Event: true, - User: true, - }, - }); - await Promise.all( - participantsMoodlePending.map(async (p) => { - if (!p.User) return; - if (!p.User.moodleId) return; + include: { + Event: true, + User: true, + }, + }); + await Promise.all( + participantsMoodlePending.map(async (p) => { + if (!p.User) return; + if (!p.User.moodleId) return; - const quizzResult = await getMoodleCourseCompletionStatus( - p.User.moodleId.toString(), - p.Event.finisherMoodleCourseId!, - ); + const quizzResult = await getMoodleCourseCompletionStatus( + p.User.moodleId.toString(), + p.Event.finisherMoodleCourseId!, + ); - if (quizzResult?.completionstatus?.completed === true) { - await handleParticipantFinished(p.Event, p, p.User); + if (quizzResult?.completionstatus?.completed === true) { + await handleParticipantFinished(p.Event, p, p.User); - return prisma.participant.update({ - where: { - id: p.id, - }, - data: { - finisherMoodleCurseCompleted: true, - statusLog: { - push: { - event: "Moodle-Kurs abgeschlossen", - timestamp: new Date(), - user: "system", + return prisma.participant.update({ + where: { + id: p.id, + }, + data: { + finisherMoodleCurseCompleted: true, + statusLog: { + push: { + event: "Moodle-Kurs abgeschlossen", + timestamp: new Date(), + user: "system", + }, }, }, - }, - }); - } - }), - ); + }); + } + }), + ); + } catch (error) { + console.error("Error updating participant Moodle results:", error); + } }; CronJob.from({ cronTime: "0 * * * *", onTick: syncMoodleIds, start: true });