Don't start application until all components were initialized
This commit is contained in:
parent
72de91cb10
commit
3d3441d6c7
2 changed files with 26 additions and 21 deletions
45
server.ts
45
server.ts
|
@ -58,7 +58,11 @@ import { initDatabaseModels } from './server/initializers/database'
|
||||||
import { migrate } from './server/initializers/migrator'
|
import { migrate } from './server/initializers/migrator'
|
||||||
migrate()
|
migrate()
|
||||||
.then(() => initDatabaseModels(false))
|
.then(() => initDatabaseModels(false))
|
||||||
.then(() => onDatabaseInitDone())
|
.then(() => startApplication())
|
||||||
|
.catch(err => {
|
||||||
|
logger.error('Cannot start application.', { err })
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
|
||||||
// ----------- PeerTube modules -----------
|
// ----------- PeerTube modules -----------
|
||||||
import { installApplication } from './server/initializers'
|
import { installApplication } from './server/initializers'
|
||||||
|
@ -179,30 +183,29 @@ app.use(function (err, req, res, next) {
|
||||||
|
|
||||||
// ----------- Run -----------
|
// ----------- Run -----------
|
||||||
|
|
||||||
function onDatabaseInitDone () {
|
async function startApplication () {
|
||||||
const port = CONFIG.LISTEN.PORT
|
const port = CONFIG.LISTEN.PORT
|
||||||
|
|
||||||
installApplication()
|
await installApplication()
|
||||||
.then(() => {
|
|
||||||
// ----------- Make the server listening -----------
|
|
||||||
server.listen(port, () => {
|
|
||||||
// Emailer initialization and then job queue initialization
|
|
||||||
Emailer.Instance.init()
|
|
||||||
Emailer.Instance.checkConnectionOrDie()
|
|
||||||
.then(() => JobQueue.Instance.init())
|
|
||||||
|
|
||||||
// Caches initializations
|
// Email initialization
|
||||||
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
Emailer.Instance.init()
|
||||||
|
await Emailer.Instance.checkConnectionOrDie()
|
||||||
|
|
||||||
// Enable Schedulers
|
await JobQueue.Instance.init()
|
||||||
BadActorFollowScheduler.Instance.enable()
|
|
||||||
RemoveOldJobsScheduler.Instance.enable()
|
|
||||||
|
|
||||||
// Redis initialization
|
// Caches initializations
|
||||||
Redis.Instance.init()
|
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
||||||
|
|
||||||
logger.info('Server listening on port %d', port)
|
// Enable Schedulers
|
||||||
logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
|
BadActorFollowScheduler.Instance.enable()
|
||||||
})
|
RemoveOldJobsScheduler.Instance.enable()
|
||||||
})
|
|
||||||
|
// Redis initialization
|
||||||
|
Redis.Instance.init()
|
||||||
|
|
||||||
|
// Make server listening
|
||||||
|
server.listen(port)
|
||||||
|
logger.info('Server listening on port %d', port)
|
||||||
|
logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@ class Emailer {
|
||||||
async checkConnectionOrDie () {
|
async checkConnectionOrDie () {
|
||||||
if (!this.transporter) return
|
if (!this.transporter) return
|
||||||
|
|
||||||
|
logger.info('Testing SMTP server...')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const success = await this.transporter.verify()
|
const success = await this.transporter.verify()
|
||||||
if (success !== true) this.dieOnConnectionFailure()
|
if (success !== true) this.dieOnConnectionFailure()
|
||||||
|
|
Loading…
Reference in a new issue