feat: run worker same process non windows
This commit is contained in:
@@ -112,6 +112,9 @@ let workerProcess: any;
|
|||||||
let recordingWorkerProcess: any;
|
let recordingWorkerProcess: any;
|
||||||
|
|
||||||
if (!isProduction && require.main === module) {
|
if (!isProduction && require.main === module) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
console.log('Using forked processes for Windows');
|
||||||
|
|
||||||
workerProcess = fork(workerPath, [], {
|
workerProcess = fork(workerPath, [], {
|
||||||
execArgv: [
|
execArgv: [
|
||||||
'--require', 'ts-node/register',
|
'--require', 'ts-node/register',
|
||||||
@@ -161,6 +164,18 @@ if (!isProduction && require.main === module) {
|
|||||||
recordingWorkerProcess.on('exit', (code: any) => {
|
recordingWorkerProcess.on('exit', (code: any) => {
|
||||||
console.log(`Recording worker exited with code: ${code}`);
|
console.log(`Recording worker exited with code: ${code}`);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
console.log('Running workers in same process for Unix-like systems');
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await import('./schedule-worker');
|
||||||
|
await import('./pgboss-worker');
|
||||||
|
console.log('Workers started in main process for memory sharing');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to start workers in main process:', error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
@@ -231,7 +246,7 @@ if (require.main === module) {
|
|||||||
console.error('Error closing PostgreSQL connection pool:', error);
|
console.error('Error closing PostgreSQL connection pool:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isProduction) {
|
if (!isProduction && process.platform === 'win32') {
|
||||||
if (workerProcess) workerProcess.kill();
|
if (workerProcess) workerProcess.kill();
|
||||||
if (recordingWorkerProcess) recordingWorkerProcess.kill();
|
if (recordingWorkerProcess) recordingWorkerProcess.kill();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user