mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-21 23:41:22 +00:00
Merge pull request #1543 from hedgedoc/feat/db_reconnect
This commit is contained in:
commit
84b3504911
2 changed files with 33 additions and 13 deletions
19
app.js
19
app.js
|
@ -272,6 +272,9 @@ function startListen () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxDBTries = 30
|
||||||
|
let currentDBTry = 1
|
||||||
|
function syncAndListen () {
|
||||||
// sync db then start listen
|
// sync db then start listen
|
||||||
models.sequelize.authenticate().then(function () {
|
models.sequelize.authenticate().then(function () {
|
||||||
models.runMigrations().then(() => {
|
models.runMigrations().then(() => {
|
||||||
|
@ -283,10 +286,24 @@ models.sequelize.authenticate().then(function () {
|
||||||
if (!notes || notes.length <= 0) return startListen()
|
if (!notes || notes.length <= 0) return startListen()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
throw new Error('server still not ready after db synced')
|
logger.error('server still not ready after db synced')
|
||||||
|
process.exit(1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
if (currentDBTry < maxDBTries) {
|
||||||
|
logger.warn(`Database cannot be reached. Try ${currentDBTry} of ${maxDBTries}.`)
|
||||||
|
currentDBTry++
|
||||||
|
setTimeout(function () {
|
||||||
|
syncAndListen()
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
logger.error('Cannot reach database! Exiting.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
syncAndListen()
|
||||||
|
|
||||||
// log uncaught exception
|
// log uncaught exception
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function (err) {
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
If you want to continue using Google Analytics or Disqus, you can re-enable them in the config.
|
If you want to continue using Google Analytics or Disqus, you can re-enable them in the config.
|
||||||
See [the docs](https://docs.hedgedoc.org/configuration/#web-security-aspects) for details.
|
See [the docs](https://docs.hedgedoc.org/configuration/#web-security-aspects) for details.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- HedgeDoc now automatically retries connecting to the database up to 30 times on startup.
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- Fix crash when trying to read the current Git commit on startup
|
- Fix crash when trying to read the current Git commit on startup
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue