-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
051c8dc
commit 4d22c84
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Worker } from 'worker_threads'; | ||
|
||
const numWorkers = 2; | ||
const workers = []; | ||
|
||
import path from 'path'; | ||
|
||
const __dirname = path.resolve(); | ||
|
||
function getDynamicPath(): string { | ||
const loc = path.resolve(__dirname, 'build/src/services/redis/subscriber.js'); | ||
return loc; | ||
} | ||
|
||
for (let i = 0; i < numWorkers; i++) { | ||
const worker = new Worker(getDynamicPath()); | ||
workers.push(worker); | ||
|
||
worker.on('exit', (code) => { | ||
if (code !== 0) { | ||
console.error(`Worker stopped with exit code ${code}`); | ||
} | ||
}); | ||
|
||
worker.on('error', (error) => { | ||
console.error('Worker error:', error); | ||
}); | ||
} | ||
|
||
process.on('SIGINT', () => { | ||
console.log('Received SIGINT. Shutting down...'); | ||
stopWorkers(); | ||
}); | ||
|
||
process.on('SIGTERM', () => { | ||
console.log('Received SIGTERM. Shutting down...'); | ||
stopWorkers(); | ||
}); | ||
|
||
function stopWorkers(): void { | ||
for (const worker of workers) { | ||
worker.postMessage('stop'); | ||
} | ||
} | ||
|
||
function log(): string { | ||
return 'Worker threads started'; | ||
} | ||
|
||
export default log; |