2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-02-27 02:07:39 +00:00
|
|
|
import cluster from 'node:cluster';
|
2024-06-06 02:20:54 +00:00
|
|
|
import * as Sentry from '@sentry/node';
|
|
|
|
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
2023-01-23 11:07:48 +00:00
|
|
|
import { envOption } from '@/env.js';
|
2024-06-06 02:20:54 +00:00
|
|
|
import { loadConfig } from '@/config.js';
|
2023-01-23 11:07:48 +00:00
|
|
|
import { jobQueue, server } from './common.js';
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Init worker process
|
|
|
|
*/
|
|
|
|
export async function workerMain() {
|
2024-06-06 02:20:54 +00:00
|
|
|
const config = loadConfig();
|
|
|
|
|
|
|
|
if (config.sentryForBackend) {
|
|
|
|
Sentry.init({
|
|
|
|
integrations: [
|
|
|
|
...(config.sentryForBackend.enableNodeProfiling ? [nodeProfilingIntegration()] : []),
|
|
|
|
],
|
|
|
|
|
|
|
|
// Performance Monitoring
|
|
|
|
tracesSampleRate: 1.0, // Capture 100% of the transactions
|
|
|
|
|
|
|
|
// Set sampling rate for profiling - this is relative to tracesSampleRate
|
|
|
|
profilesSampleRate: 1.0,
|
|
|
|
|
|
|
|
maxBreadcrumbs: 0,
|
|
|
|
|
|
|
|
...config.sentryForBackend.options,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-23 11:07:48 +00:00
|
|
|
if (envOption.onlyServer) {
|
|
|
|
await server();
|
|
|
|
} else if (envOption.onlyQueue) {
|
|
|
|
await jobQueue();
|
|
|
|
} else {
|
|
|
|
await jobQueue();
|
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
if (cluster.isWorker) {
|
|
|
|
// Send a 'ready' message to parent process
|
2019-04-12 16:43:22 +00:00
|
|
|
process.send!('ready');
|
2019-04-07 12:50:36 +00:00
|
|
|
}
|
|
|
|
}
|