feat: run worker same process non windows
This commit is contained in:
@@ -112,55 +112,70 @@ let workerProcess: any;
|
|||||||
let recordingWorkerProcess: any;
|
let recordingWorkerProcess: any;
|
||||||
|
|
||||||
if (!isProduction && require.main === module) {
|
if (!isProduction && require.main === module) {
|
||||||
workerProcess = fork(workerPath, [], {
|
if (process.platform === 'win32') {
|
||||||
execArgv: [
|
console.log('Using forked processes for Windows');
|
||||||
'--require', 'ts-node/register',
|
|
||||||
'--inspect=0'
|
workerProcess = fork(workerPath, [], {
|
||||||
],
|
execArgv: [
|
||||||
env: {
|
'--require', 'ts-node/register',
|
||||||
...process.env,
|
'--inspect=0'
|
||||||
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
|
],
|
||||||
"module": "commonjs",
|
env: {
|
||||||
"moduleResolution": "node",
|
...process.env,
|
||||||
"esModuleInterop": true
|
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
|
||||||
})
|
"module": "commonjs",
|
||||||
}
|
"moduleResolution": "node",
|
||||||
});
|
"esModuleInterop": true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
workerProcess.on('message', (message: any) => {
|
workerProcess.on('message', (message: any) => {
|
||||||
console.log(`Message from worker: ${message}`);
|
console.log(`Message from worker: ${message}`);
|
||||||
});
|
});
|
||||||
workerProcess.on('error', (error: any) => {
|
workerProcess.on('error', (error: any) => {
|
||||||
console.error(`Error in worker: ${error}`);
|
console.error(`Error in worker: ${error}`);
|
||||||
});
|
});
|
||||||
workerProcess.on('exit', (code: any) => {
|
workerProcess.on('exit', (code: any) => {
|
||||||
console.log(`Worker exited with code: ${code}`);
|
console.log(`Worker exited with code: ${code}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
recordingWorkerProcess = fork(recordingWorkerPath, [], {
|
recordingWorkerProcess = fork(recordingWorkerPath, [], {
|
||||||
execArgv: [
|
execArgv: [
|
||||||
'--require', 'ts-node/register',
|
'--require', 'ts-node/register',
|
||||||
'--inspect=0'
|
'--inspect=0'
|
||||||
],
|
],
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
|
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
recordingWorkerProcess.on('message', (message: any) => {
|
recordingWorkerProcess.on('message', (message: any) => {
|
||||||
console.log(`Message from recording worker: ${message}`);
|
console.log(`Message from recording worker: ${message}`);
|
||||||
});
|
});
|
||||||
recordingWorkerProcess.on('error', (error: any) => {
|
recordingWorkerProcess.on('error', (error: any) => {
|
||||||
console.error(`Error in recording worker: ${error}`);
|
console.error(`Error in recording worker: ${error}`);
|
||||||
});
|
});
|
||||||
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