retry spawn with longer timeout

This commit is contained in:
Erik 2023-12-10 23:00:29 +02:00
parent 9446a4dc89
commit 4ab7f33767
2 changed files with 24 additions and 1 deletions

View File

@ -134,13 +134,35 @@ class Controller extends EventEmitter
} }
// const promises = []; // const promises = [];
const retry: Shard[] = [];
for (let i = 0; i < shardCount; i++) for (let i = 0; i < shardCount; i++)
{ {
const shard = this.createShard(shardCount); const shard = this.createShard(shardCount);
await shard.spawn(90_000); try
{
await shard.spawn(90_000);
}
catch (err)
{
this.logger.error(err as Error);
this.logger.info('Retrying shard', i);
retry.push(shard);
}
// promises.push(); // promises.push();
} }
for (const shard of retry)
{
try
{
await shard.spawn(120_000);
}
catch
{
this.logger.error(`Shard ${shard.id} failed to spawn in time`);
}
}
// await Promise.all(promises); // await Promise.all(promises);
this.#logger.status(`Shards spawned, spawned ${this.#shards.size} shards. Took ${Date.now() - start} ms`); this.#logger.status(`Shards spawned, spawned ${this.#shards.size} shards. Took ${Date.now() - start} ms`);

View File

@ -132,6 +132,7 @@ class Shard extends EventEmitter
{ {
const cleanup = () => const cleanup = () =>
{ {
this.#process?.kill();
clearTimeout(spawnTimeoutTimer); // eslint-disable-line @typescript-eslint/no-use-before-define clearTimeout(spawnTimeoutTimer); // eslint-disable-line @typescript-eslint/no-use-before-define
this.off('ready', onReady); // eslint-disable-line @typescript-eslint/no-use-before-define this.off('ready', onReady); // eslint-disable-line @typescript-eslint/no-use-before-define
this.off('disconnect', onDisconnect); // eslint-disable-line @typescript-eslint/no-use-before-define this.off('disconnect', onDisconnect); // eslint-disable-line @typescript-eslint/no-use-before-define