Skip to content

Commit

Permalink
feat(schedule): error handling and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawei397 committed Nov 10, 2023
1 parent ba86952 commit 5011491
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions modules/schedule/src/scheduler.explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ScheduleExplorer {
try {
await instance[methodName]();
} catch (err) {
console.error("SchedulerError", err);
console.error("ScheduleCronError", err);
}
});
});
Expand All @@ -47,7 +47,9 @@ export class ScheduleExplorer {
try {
await instance[methodName]();
} catch (err) {
console.error("SchedulerError", err);
console.error("ScheduleTimeoutError", err);
} finally {
schedulerRegistry.timeCaches.delete(timeKey);
}
}, delay);
schedulerRegistry.registerTime(timeKey, jobName);
Expand All @@ -70,7 +72,7 @@ export class ScheduleExplorer {
try {
await instance[methodName]();
} catch (err) {
console.error("SchedulerError", err);
console.error("ScheduleIntervalError", err);
}
}, delay);
schedulerRegistry.registerTime(timeKey, jobName);
Expand Down
18 changes: 18 additions & 0 deletions modules/schedule/src/scheduler.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,35 @@ class SchedulerRegistry {
this.timeCaches.set(name, timeKey);
}

clearTimeoutByKey(timeKey: number) {
this.timeCaches.forEach((key, name) => {
if (key === timeKey) {
this.clearTimeout(name);
}
});
}

clearIntervalByKey(timeKey: number) {
this.timeCaches.forEach((key, name) => {
if (key === timeKey) {
this.clearInterval(name);
}
});
}

clearTimeout(name: string) {
const key = this.timeCaches.get(name);
if (key) {
clearTimeout(key);
this.timeCaches.delete(name);
}
}

clearInterval(name: string) {
const key = this.timeCaches.get(name);
if (key) {
clearInterval(key);
this.timeCaches.delete(name);
}
}

Expand Down

0 comments on commit 5011491

Please sign in to comment.