🔪🐛 Fix shutdown being called before init, fix duplicate SIGNIT catch
All checks were successful
Deploy application / deploy (push) Successful in 16s

This commit is contained in:
Martin Berg Alstad 2025-02-13 21:14:51 +01:00
parent 4367c24fb0
commit 95ddcbaf13
Signed by: martials
GPG Key ID: A3824877B269F2E2

View File

@ -28,7 +28,6 @@ async function main(): Promise<void> {
await runCronJob(bank)
}
// TODO log the days the transactions are fetched
export async function moveTransactions(
actual: Actual,
bank: Bank,
@ -81,31 +80,32 @@ async function runOnce(bank: Bank) {
}
async function runCronJob(bank: Bank): Promise<void> {
let actual: Actual | undefined
let cronJob: CronJob | undefined
logger.info("Waiting for CronJob to start")
try {
// TODO move try-catch inside closure?
cronJob = cronJobDaily(async () => {
const cronJob = cronJobDaily(async () => {
let actual: Actual | undefined
try {
actual = await ActualImpl.init()
await moveTransactions(actual, bank)
})
registerInterrupt(bank, cronJob)
} catch (exception) {
logger.error(exception, "Caught exception at CronJob, shutting down!")
await shutdown(bank, cronJob)
} finally {
// TODO shuts down immediatly, move into closure
await actual?.shutdown()
}
} catch (exception) {
logger.error(exception, "Caught exception at CronJob, shutting down!")
await shutdown(bank, cronJob)
} finally {
await actual?.shutdown()
}
})
registerInterrupt(bank, cronJob)
}
let isShuttingDown = false
function registerInterrupt(
bank: Bank,
cronJob: CronJob | undefined = undefined,
): void {
process.on("SIGINT", async () => {
if (isShuttingDown) return
isShuttingDown = true
logger.info("Caught interrupt signal")
await shutdown(bank, cronJob)
})