first commit

This commit is contained in:
Giancarmine Salucci
2025-04-15 10:53:28 +02:00
commit d6365855b6
6 changed files with 500 additions and 0 deletions

21
worker.js Normal file
View File

@@ -0,0 +1,21 @@
const { parentPort, workerData } = require('worker_threads');
const axios = require('axios');
let { url, body, headers, run, id } = workerData;
const workerFunction = async () => {
parentPort.postMessage({ status: 'starting', id, url, body, headers });
while (run) {
try {
await axios.post(url, body, { headers });
parentPort.postMessage({ status: 'success' });
} catch (error) {
if(error.status === 500) {
parentPort.postMessage({ status: 'recoverable-error', error: `Unable to POST at ${url} status: ${error.status}, message: ${error.message}`});
} else {
throw new Error(`Unable to POST at ${url} status: ${error.status}, message: ${error.message}`);
}
}
}
};
workerFunction();