first commit
This commit is contained in:
33
main.js
Normal file
33
main.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const {workerFactory, onMessage, onError, onExit} = require('./util');
|
||||
const THREAD_COUNT = 4; // Number of threads you want to run
|
||||
|
||||
|
||||
const data = {
|
||||
url: 'https://care.drmax.eu/it/pharmacy/698Edb',
|
||||
body: '__VIEWSTATE=%2FwEPDwULLTE5MzAwNTM5OTlkZJTEOkK8qrP%2BTqGLIsu2BOyqAooELsVS8rKLByxL86Wb&__VIEWSTATEGENERATOR=221C5153&cpt=Care&lang=it&type=698Edb&votes=Odeslat',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Origin': 'https://care.drmax.eu/it/pharmacies'
|
||||
},
|
||||
run: true
|
||||
};
|
||||
|
||||
|
||||
const workers = [...Array(THREAD_COUNT).keys()].map((id) => workerFactory(
|
||||
{ id, ...data },
|
||||
onMessage,
|
||||
onError,
|
||||
onExit
|
||||
));
|
||||
console.log(`main\t✅ Initialized ${workers.length} workers.`);
|
||||
|
||||
// Handle Ctrl+C
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('\nmain\t🛑 Terminating workers...');
|
||||
|
||||
// Gracefully terminate all workers
|
||||
await Promise.all(workers.map(worker => worker.terminate()));
|
||||
|
||||
console.log('main\t✅ All workers terminated. Exiting.');
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user