diff options
author | Florian Dold <florian@dold.me> | 2024-04-22 23:37:56 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-04-22 23:37:56 +0200 |
commit | 00095769c8f047ddad204c14379839efbbc8640d (patch) | |
tree | ca99dfec044daf904c56f31d571dbddae469d5e7 | |
parent | a181ee06e4b52cb35e00ff8c86acff315135faf2 (diff) | |
download | wallet-core-00095769c8f047ddad204c14379839efbbc8640d.tar.xz |
wallet-core: only load tasks from DB once
-rw-r--r-- | packages/taler-wallet-core/src/shepherd.ts | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts index aae6d5a18..f512d53a4 100644 --- a/packages/taler-wallet-core/src/shepherd.ts +++ b/packages/taler-wallet-core/src/shepherd.ts @@ -179,7 +179,13 @@ export class TaskSchedulerImpl implements TaskScheduler { if (this.isRunning) { return; } - await this.loadTasksFromDb(); + this.isRunning = true; + try { + await this.loadTasksFromDb(); + } catch (e) { + this.isRunning = false; + throw e; + } this.run() .catch((e) => { logger.error("error running task loop"); @@ -187,14 +193,13 @@ export class TaskSchedulerImpl implements TaskScheduler { }) .then(() => { logger.info("done running task loop"); + this.isRunning = false; }); } isIdle(): boolean { let alive = false; const taskIds = [...this.sheps.keys()]; - logger.info(`current task IDs: ${j2s(taskIds)}`); - logger.info(`sheps: ${this.sheps.size}`); for (const taskId of taskIds) { if (taskGivesLiveness(taskId)) { alive = true; @@ -206,13 +211,7 @@ export class TaskSchedulerImpl implements TaskScheduler { } private async run(): Promise<void> { - if (this.isRunning) { - throw Error("task loop already running"); - } logger.info("Running task loop."); - this.isRunning = true; - await this.loadTasksFromDb(); - logger.info("loaded!"); logger.info(`sheps: ${this.sheps.size}`); while (true) { if (this.ws.stopped) { @@ -228,7 +227,6 @@ export class TaskSchedulerImpl implements TaskScheduler { await this.iterCond.wait(); } - this.isRunning = false; logger.info("Done with task loop."); } |