aboutsummaryrefslogtreecommitdiffhomepage
path: root/server.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-04 11:04:14 +0200
committerChocobozzz <me@florianbigard.com>2018-04-04 11:04:14 +0200
commit3d3441d6c7a5646388ab0a77acad57fdb63b9d32 (patch)
tree4fa3d1a52fc06d0a6ab65d5fdd7a00628f92ae95 /server.ts
parent72de91cb109b091fff607fbb0c6968bb8a1c97f3 (diff)
downloadPeerTube-3d3441d6c7a5646388ab0a77acad57fdb63b9d32.tar.gz
PeerTube-3d3441d6c7a5646388ab0a77acad57fdb63b9d32.tar.zst
PeerTube-3d3441d6c7a5646388ab0a77acad57fdb63b9d32.zip
Don't start application until all components were initialized
Diffstat (limited to 'server.ts')
-rw-r--r--server.ts53
1 files changed, 28 insertions, 25 deletions
diff --git a/server.ts b/server.ts
index b307e67a1..97941c958 100644
--- a/server.ts
+++ b/server.ts
@@ -58,7 +58,11 @@ import { initDatabaseModels } from './server/initializers/database'
58import { migrate } from './server/initializers/migrator' 58import { migrate } from './server/initializers/migrator'
59migrate() 59migrate()
60 .then(() => initDatabaseModels(false)) 60 .then(() => initDatabaseModels(false))
61 .then(() => onDatabaseInitDone()) 61 .then(() => startApplication())
62 .catch(err => {
63 logger.error('Cannot start application.', { err })
64 process.exit(-1)
65 })
62 66
63// ----------- PeerTube modules ----------- 67// ----------- PeerTube modules -----------
64import { installApplication } from './server/initializers' 68import { installApplication } from './server/initializers'
@@ -179,30 +183,29 @@ app.use(function (err, req, res, next) {
179 183
180// ----------- Run ----------- 184// ----------- Run -----------
181 185
182function onDatabaseInitDone () { 186async function startApplication () {
183 const port = CONFIG.LISTEN.PORT 187 const port = CONFIG.LISTEN.PORT
184 188
185 installApplication() 189 await installApplication()
186 .then(() => { 190
187 // ----------- Make the server listening ----------- 191 // Email initialization
188 server.listen(port, () => { 192 Emailer.Instance.init()
189 // Emailer initialization and then job queue initialization 193 await Emailer.Instance.checkConnectionOrDie()
190 Emailer.Instance.init() 194
191 Emailer.Instance.checkConnectionOrDie() 195 await JobQueue.Instance.init()
192 .then(() => JobQueue.Instance.init()) 196
193 197 // Caches initializations
194 // Caches initializations 198 VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
195 VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE) 199
196 200 // Enable Schedulers
197 // Enable Schedulers 201 BadActorFollowScheduler.Instance.enable()
198 BadActorFollowScheduler.Instance.enable() 202 RemoveOldJobsScheduler.Instance.enable()
199 RemoveOldJobsScheduler.Instance.enable() 203
200 204 // Redis initialization
201 // Redis initialization 205 Redis.Instance.init()
202 Redis.Instance.init() 206
203 207 // Make server listening
204 logger.info('Server listening on port %d', port) 208 server.listen(port)
205 logger.info('Web server: %s', CONFIG.WEBSERVER.URL) 209 logger.info('Server listening on port %d', port)
206 }) 210 logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
207 })
208} 211}