mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-11-25 15:04:08 +00:00
Handle network error when fetching latest block
This commit is contained in:
parent
86609631c9
commit
2126c17f0d
@ -191,6 +191,7 @@ export class EventWatcher {
|
|||||||
|
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
try {
|
||||||
const { block: latestBlock } = await this._ethClient.getBlockByHash();
|
const { block: latestBlock } = await this._ethClient.getBlockByHash();
|
||||||
|
|
||||||
// Process block if it is blockProcessingOffset blocks behind latest block
|
// Process block if it is blockProcessingOffset blocks behind latest block
|
||||||
@ -199,12 +200,18 @@ export class EventWatcher {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(`Latest block: ${latestBlock.number}; retry next block to process: ${blockNumber + 1} after ${this._config.jobQueue.blockDelayInMilliSecs}ms`);
|
log(`Latest block number fetched: ${latestBlock.number}`);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
log(`Error while triggering processing for next block: ${blockNumber + 1}`);
|
||||||
|
log(err);
|
||||||
|
} finally {
|
||||||
|
log(`Retry next block to process: ${blockNumber + 1} after ${this._config.jobQueue.blockDelayInMilliSecs}ms`);
|
||||||
await wait(this._config.jobQueue.blockDelayInMilliSecs);
|
await wait(this._config.jobQueue.blockDelayInMilliSecs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleShutdown (): void {
|
handleShutdown (): void {
|
||||||
process.on('SIGINT', this._processShutdown.bind(this));
|
process.on('SIGINT', this._processShutdown.bind(this));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user