From fb122015cb266662eec6ff733079bda77b3ba8d3 Mon Sep 17 00:00:00 2001 From: Kata Date: Sun, 2 Feb 2020 14:30:50 -0500 Subject: [PATCH] fix(DiscordService): retry bootstrap process 10 times --- Server/services/discord.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Server/services/discord.js b/Server/services/discord.js index b6edcf4..fac3410 100644 --- a/Server/services/discord.js +++ b/Server/services/discord.js @@ -31,6 +31,9 @@ class DiscordService extends Service { Authorization: `Shared ${this.rpcSecret}`, } + this.bootstrapRetries = 0 + this.bootstrapRetriesMax = 10 + this.bootstrap().catch(e => { console.error(`bootstrap failure`, e) process.exit(-1) @@ -38,11 +41,22 @@ class DiscordService extends Service { } async bootstrap() { - const ownUser = await this.rpc.ownUser(new Empty(), this.sharedHeaders) - this.ownUser = ownUser.toObject() - - const listGuilds = await this.rpc.listGuilds(new Empty(), this.sharedHeaders) - this.syncGuilds(listGuilds.toObject().guildsList) + setTimeout(() => { + try { + const ownUser = await this.rpc.ownUser(new Empty(), this.sharedHeaders) + this.ownUser = ownUser.toObject() + + const listGuilds = await this.rpc.listGuilds(new Empty(), this.sharedHeaders) + this.syncGuilds(listGuilds.toObject().guildsList) + } catch (e) { + this.bootstrapRetries++ + if (this.bootstrapRetries < this.bootstrapRetriesMax) { + return this.bootstrap() + } else { + throw e + } + } + }, 1000) } ownGm(server) {