Skip to content

Commit 5f44ec6

Browse files
joojisremagpie
authored andcommitted
Never cancel the sync scheduler while worker's run()
Currently, worker can stop due to various errors. But, there are not only HTTP connection errors but also many errors that worker can retry it later, such as DB connection error or timeout, etc.
1 parent 2d3a5da commit 5f44ec6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/worker/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@ export default class Worker {
4040
}
4141

4242
public run = async () => {
43+
let lastError: Error | null = null;
4344
this.watchJob = scheduleJob(this.config.watchSchedule, async () => {
4445
try {
4546
if (this.lock.isBusy(ASYNC_LOCK_KEY) === false) {
4647
await this.sync();
4748
}
49+
lastError = null;
4850
} catch (err) {
49-
const error = err as Error;
50-
if (error.message.search(/ECONNRESET|ECONNREFUSED/) >= 0) {
51-
console.error("RPC Error");
52-
} else {
53-
console.error(error);
54-
this.watchJob.cancel(false);
51+
if (
52+
lastError &&
53+
err &&
54+
lastError.name === err.name &&
55+
lastError.message === err.message
56+
) {
57+
return;
5558
}
59+
lastError = err;
60+
console.error("sync error: ", err);
5661
}
5762
});
5863
this.watchJob.invoke();

0 commit comments

Comments
 (0)