Giancarmine Salucci d6365855b6 first commit
2025-04-15 10:53:28 +02:00

21 lines
810 B
JavaScript

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();