taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 00095769c8f047ddad204c14379839efbbc8640d
parent a181ee06e4b52cb35e00ff8c86acff315135faf2
Author: Florian Dold <florian@dold.me>
Date:   Mon, 22 Apr 2024 23:37:56 +0200

wallet-core: only load tasks from DB once

Diffstat:
Mpackages/taler-wallet-core/src/shepherd.ts | 18++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git 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."); }