arguments, fixes, dockerfile, ci
Some checks failed
Build and publish farmacia-bot images / Build and push client's image to Gitea's registry (push) Successful in 38s
Build and publish farmacia-bot images / deploy_ovh (push) Failing after 5s

This commit is contained in:
Giancarmine Salucci
2025-04-15 13:10:17 +02:00
parent d6365855b6
commit b728f19570
6 changed files with 188 additions and 10 deletions

21
main.js
View File

@@ -1,6 +1,19 @@
const {workerFactory, onMessage, onError, onExit} = require('./util');
const THREAD_COUNT = 4; // Number of threads you want to run
const {workerFactory, onMessage, onError, onExit, logger} = require('./util');
const os = require('os');
let THREAD_COUNT = Math.max(1, os.cpus().length - 1);;
// Get thread count from first positional argument or use default (all cores - 1)
if (process.argv.length > 2) {
const requestedThreads = parseInt(process.argv[2], 10);
if (!isNaN(requestedThreads) && requestedThreads > 0) {
THREAD_COUNT = requestedThreads;
}
}
const startDateTime = new Date().toISOString();
console.log(`main\t🕒 Started at ${startDateTime}`);
console.log(`main\t🧵 Using ${THREAD_COUNT} worker threads`);
logger().info(`Application started with ${THREAD_COUNT} worker threads`);
const data = {
url: 'https://care.drmax.eu/it/pharmacy/698Edb',
@@ -12,7 +25,6 @@ const data = {
run: true
};
const workers = [...Array(THREAD_COUNT).keys()].map((id) => workerFactory(
{ id, ...data },
onMessage,
@@ -20,14 +32,17 @@ const workers = [...Array(THREAD_COUNT).keys()].map((id) => workerFactory(
onExit
));
console.log(`main\t✅ Initialized ${workers.length} workers.`);
logger().info(`Initialized ${workers.length} workers`);
// Handle Ctrl+C
process.on('SIGINT', async () => {
console.log('\nmain\t🛑 Terminating workers...');
logger().info('Received SIGINT signal. Terminating workers...');
// Gracefully terminate all workers
await Promise.all(workers.map(worker => worker.terminate()));
console.log('main\t✅ All workers terminated. Exiting.');
logger().info('All workers terminated. Exiting.');
process.exit(0);
});