Skip to content

Commit

Permalink
fix(workers): add retry for workers emit (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Jun 19, 2019
1 parent f6238db commit bbae8ab
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/bot/workers.ts
Expand Up @@ -179,10 +179,25 @@ class Workers {
});
if (obj && obj.socket) { obj.emit(data.event, ...data.args); }
} else {
const obj = Object.values(global[data.system]).find((o: any) => {
return o.constructor.name.toLowerCase() === data.class.toLowerCase();
}) as any;
if (obj && obj.socket) { obj.emit(data.event, ...data.args); }
try {
const obj = Object.values(global[data.system]).find((o: any) => {
return o.constructor.name.toLowerCase() === data.class.toLowerCase();
}) as any;
if (obj) {
obj.emit(data.event, ...data.args);
}
} catch (e) {
if ((data.retry || 0) < 5) {
setTimeout(() => {
data.retry = (data.retry || 0) + 1;
this.process(data);
}, 5000);
} else {
global.log.error(e.stack);
global.log.error('Something went wrong when emiting');
global.log.error(inspect(data, undefined, 5));
}
}
}
} else if ( data.type === 'crash') {
process.exit(1); // kill main thread
Expand Down

0 comments on commit bbae8ab

Please sign in to comment.