fix(DiscordService): retry bootstrap process 10 times

This commit is contained in:
41666 2020-02-02 14:30:50 -05:00
parent dc4400aa34
commit fb122015cb
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF

View file

@ -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) {