mirror of
https://github.com/paricafe/misskey.git
synced 2024-12-28 08:46:43 -06:00
Synchronize server startup
This prevents an edge case where the server begins processing inbound API / AP requests before any of the chart / management daemons are ready, potentially leading to incorrect chart statistics.
This commit is contained in:
parent
cd6c87af0c
commit
2c4fc485e4
3 changed files with 15 additions and 11 deletions
|
@ -12,21 +12,25 @@ import { QueueStatsService } from '@/daemons/QueueStatsService.js';
|
||||||
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
|
import { ServerStatsService } from '@/daemons/ServerStatsService.js';
|
||||||
import { ServerService } from '@/server/ServerService.js';
|
import { ServerService } from '@/server/ServerService.js';
|
||||||
import { MainModule } from '@/MainModule.js';
|
import { MainModule } from '@/MainModule.js';
|
||||||
|
import { envOption } from '@/env.js';
|
||||||
|
|
||||||
export async function server() {
|
export async function server() {
|
||||||
const app = await NestFactory.createApplicationContext(MainModule, {
|
const app = await NestFactory.createApplicationContext(MainModule, {
|
||||||
logger: new NestLogger(),
|
logger: new NestLogger(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
await app.get(ChartManagementService).start();
|
||||||
|
}
|
||||||
|
if (!envOption.noDaemons) {
|
||||||
|
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);
|
const serverService = app.get(ServerService);
|
||||||
await serverService.launch();
|
await serverService.launch();
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'test') {
|
|
||||||
app.get(ChartManagementService).start();
|
|
||||||
app.get(QueueStatsService).start();
|
|
||||||
app.get(ServerStatsService).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +39,8 @@ export async function jobQueue() {
|
||||||
logger: new NestLogger(),
|
logger: new NestLogger(),
|
||||||
});
|
});
|
||||||
|
|
||||||
jobQueue.get(QueueProcessorService).start();
|
await jobQueue.get(QueueProcessorService).start();
|
||||||
jobQueue.get(ChartManagementService).start();
|
await jobQueue.get(ChartManagementService).start();
|
||||||
|
|
||||||
return jobQueue;
|
return jobQueue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ export class QueueStatsService implements OnApplicationShutdown {
|
||||||
* Report queue stats regularly
|
* Report queue stats regularly
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public start(): void {
|
public async start(): Promise<void> {
|
||||||
const log = [] as any[];
|
const log = [] as any[];
|
||||||
|
|
||||||
ev.on('requestQueueStatsLog', x => {
|
ev.on('requestQueueStatsLog', x => {
|
||||||
|
@ -82,7 +82,7 @@ export class QueueStatsService implements OnApplicationShutdown {
|
||||||
activeInboxJobs = 0;
|
activeInboxJobs = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
tick();
|
await tick();
|
||||||
|
|
||||||
this.intervalId = setInterval(tick, interval);
|
this.intervalId = setInterval(tick, interval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ export class ServerStatsService implements OnApplicationShutdown {
|
||||||
if (log.length > 200) log.pop();
|
if (log.length > 200) log.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
tick();
|
await tick();
|
||||||
|
|
||||||
this.intervalId = setInterval(tick, interval);
|
this.intervalId = setInterval(tick, interval);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue