From 7d2d1671a66ad57ee8a3267a68e2cd8f42fa3063 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 5 Feb 2024 17:21:43 +0200 Subject: [PATCH 1/3] some more adjustments --- app/entry.server.tsx | 1 + app/utils/scheduler.server.ts | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/entry.server.tsx b/app/entry.server.tsx index a4895eb5a..df2d3eb0a 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -28,6 +28,7 @@ schedulerService // eslint-disable-next-line no-console console.log("Scheduler and workers registered"); }) + // eslint-disable-next-line no-console .catch((e) => console.error(e)); // === end: register scheduler and workers === diff --git a/app/utils/scheduler.server.ts b/app/utils/scheduler.server.ts index f5538ae24..722512d78 100644 --- a/app/utils/scheduler.server.ts +++ b/app/utils/scheduler.server.ts @@ -8,19 +8,33 @@ declare global { var scheduler: PgBoss; } +let isInit = false; export const init = async () => { - if (!scheduler) { - if (NODE_ENV === "production") { - scheduler = new PgBoss(DIRECT_URL); - } else { - if (!global.scheduler) { - global.scheduler = new PgBoss(DIRECT_URL); + try { + if (!scheduler) { + if (NODE_ENV === "production") { + scheduler = new PgBoss(DIRECT_URL); + } else { + if (!global.scheduler) { + global.scheduler = new PgBoss(DIRECT_URL); + } + scheduler = global.scheduler; } - scheduler = global.scheduler; + + if (isInit) { + return; + } + + await scheduler.start(); + isInit = true; } - await scheduler.start(); + return; + } catch (e) { + // eslint-disable-next-line no-console + console.error(e); } - return; }; +init(); + export { scheduler }; From eb8bfe7a206d1a5d06e23412b303487be1d02137 Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 5 Feb 2024 17:24:43 +0200 Subject: [PATCH 2/3] cleanup --- app/utils/scheduler.server.ts | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/app/utils/scheduler.server.ts b/app/utils/scheduler.server.ts index 722512d78..8c408a231 100644 --- a/app/utils/scheduler.server.ts +++ b/app/utils/scheduler.server.ts @@ -4,37 +4,22 @@ import { DIRECT_URL, NODE_ENV } from "../utils/env"; let scheduler!: PgBoss; declare global { - // eslint-disable-next-line no-var var scheduler: PgBoss; } -let isInit = false; export const init = async () => { - try { - if (!scheduler) { - if (NODE_ENV === "production") { - scheduler = new PgBoss(DIRECT_URL); - } else { - if (!global.scheduler) { - global.scheduler = new PgBoss(DIRECT_URL); - } - scheduler = global.scheduler; + if (!scheduler) { + if (NODE_ENV === "production") { + scheduler = new PgBoss(DIRECT_URL); + } else { + if (!global.scheduler) { + global.scheduler = new PgBoss(DIRECT_URL); } - - if (isInit) { - return; - } - - await scheduler.start(); - isInit = true; + scheduler = global.scheduler; } - return; - } catch (e) { - // eslint-disable-next-line no-console - console.error(e); + await scheduler.start(); } + return; }; -init(); - export { scheduler }; From 4ce38bfefe5b894e60e563841eceb04ad1270bcf Mon Sep 17 00:00:00 2001 From: Donkoko Date: Mon, 5 Feb 2024 17:38:53 +0200 Subject: [PATCH 3/3] adding counter for registeringWorkers --- app/modules/booking/worker.server.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/modules/booking/worker.server.ts b/app/modules/booking/worker.server.ts index b8df21381..0a8051cc1 100644 --- a/app/modules/booking/worker.server.ts +++ b/app/modules/booking/worker.server.ts @@ -14,7 +14,10 @@ import type { SchedulerData } from "./types"; /** ===== start: listens and creates chain of jobs for a given booking ===== */ +let counter = 0; export const registerBookingWorkers = () => { + console.log(`called registerBookingWorkers ${++counter} `); + /** Check-out reminder */ scheduler.work( schedulerKeys.checkoutReminder,