mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 12:19:10 +00:00
[server] retry the SQL connection if it isn't immediately awake on start
this prevents `yarn dev` from erroring out since postgres takes more than 0ms to start.
This commit is contained in:
parent
10d5979ce1
commit
a273292d97
1 changed files with 12 additions and 1 deletions
|
@ -13,6 +13,7 @@ import PresentationService from './services/presentation'
|
|||
import RPCServer from './rpc'
|
||||
import fetchModels, { type Models } from './models'
|
||||
import fetchApis from './api'
|
||||
import retry from 'async-retry'
|
||||
|
||||
import type SocketIO from 'socket.io'
|
||||
import type KoaApp, { Context } from 'koa'
|
||||
|
@ -113,8 +114,18 @@ class Roleypoly {
|
|||
this.ctx.sql = sequelize
|
||||
this.M = fetchModels(sequelize)
|
||||
this.ctx.M = this.M
|
||||
|
||||
await retry(async bail => {
|
||||
try {
|
||||
await sequelize.authenticate()
|
||||
} catch (e) {
|
||||
log.error('sequelize failed to connect.', e.message)
|
||||
throw e
|
||||
}
|
||||
})
|
||||
|
||||
if (!process.env.DB_NO_SYNC) {
|
||||
await sequelize.sync()
|
||||
await this.ctx.sql.sync()
|
||||
}
|
||||
|
||||
this.ctx.server = new ServerService(this.ctx)
|
||||
|
|
Loading…
Add table
Reference in a new issue