Skip to content

Commit

Permalink
[core] log errors during periodic and one time jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
devlikepro committed Oct 1, 2024
1 parent 2e01692 commit d6b8758
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/utils/SingleDelayedJobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ export class SingleDelayedJobRunner {

this.timeout = setTimeout(() => {
this.logger.debug(`Running job...`);
fn().finally(() => {
this.timeout = null;
this.logger.debug(`Job finished`);
});
fn()
.catch((error) => {
this.logger.error(`Job failed: ${error}`);
this.logger.error(error.stack);
})
.finally(() => {
this.timeout = null;
this.logger.debug(`Job finished`);
});
}, this.timeoutMs);
this.logger.info(`Job scheduled with timeout ${this.timeoutMs} ms`);
return true;
Expand Down
13 changes: 9 additions & 4 deletions src/utils/SinglePeriodicJobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ export class SinglePeriodicJobRunner {

this.isWorking = true;
this.logger.debug('Running job...');
fn().finally(() => {
this.isWorking = false;
this.logger.debug(`Job finished`);
});
fn()
.catch((error) => {
this.logger.error(`Job failed: ${error}`);
this.logger.error(error.stack);
})
.finally(() => {
this.isWorking = false;
this.logger.debug(`Job finished`);
});
}, this.intervalMs);
this.logger.info(`Job started with interval ${this.intervalMs} ms`);
return true;
Expand Down

0 comments on commit d6b8758

Please sign in to comment.