diff --git a/packages/backend/src/boot/common.ts b/packages/backend/src/boot/common.ts index 268c07582d..f5b50a2b93 100644 --- a/packages/backend/src/boot/common.ts +++ b/packages/backend/src/boot/common.ts @@ -18,15 +18,16 @@ export async function server() { logger: new NestLogger(), }); + if (process.env.NODE_ENV !== 'test') { + await app.get(ChartManagementService).start(); + await app.get(QueueStatsService).start(); + await app.get(ServerStatsService).start(); + } + + // Start server last so the other services can register hooks first const serverService = app.get(ServerService); await serverService.launch(); - if (process.env.NODE_ENV !== 'test') { - app.get(ChartManagementService).start(); - app.get(QueueStatsService).start(); - app.get(ServerStatsService).start(); - } - return app; } @@ -35,8 +36,8 @@ export async function jobQueue() { logger: new NestLogger(), }); - jobQueue.get(QueueProcessorService).start(); - jobQueue.get(ChartManagementService).start(); + await jobQueue.get(QueueProcessorService).start(); + await jobQueue.get(ChartManagementService).start(); return jobQueue; } diff --git a/packages/backend/src/daemons/QueueStatsService.ts b/packages/backend/src/daemons/QueueStatsService.ts index ede104b9fe..77fcd71337 100644 --- a/packages/backend/src/daemons/QueueStatsService.ts +++ b/packages/backend/src/daemons/QueueStatsService.ts @@ -33,7 +33,7 @@ export class QueueStatsService implements OnApplicationShutdown { * Report queue stats regularly */ @bindThis - public start(): void { + public async start(): Promise { const log = [] as any[]; ev.on('requestQueueStatsLog', x => { @@ -82,7 +82,7 @@ export class QueueStatsService implements OnApplicationShutdown { activeInboxJobs = 0; }; - tick(); + await tick(); this.intervalId = setInterval(tick, interval); } diff --git a/packages/backend/src/daemons/ServerStatsService.ts b/packages/backend/src/daemons/ServerStatsService.ts index d229efb123..63b50f9f69 100644 --- a/packages/backend/src/daemons/ServerStatsService.ts +++ b/packages/backend/src/daemons/ServerStatsService.ts @@ -68,7 +68,7 @@ export class ServerStatsService implements OnApplicationShutdown { if (log.length > 200) log.pop(); }; - tick(); + await tick(); this.intervalId = setInterval(tick, interval); }