integracion del setTimeout y filtro de error
This commit is contained in:
parent
ab32d034bd
commit
693d60bd1d
|
@ -26,7 +26,7 @@ async function getConnectionWithRetries(retries = 3, delay = 5000) {
|
|||
let attempt = 0;
|
||||
while (attempt < retries) {
|
||||
try {
|
||||
return await pool.getConnection();
|
||||
return await pool.getConnection();
|
||||
} catch (error) {
|
||||
attempt++;
|
||||
if (attempt >= retries)
|
||||
|
@ -43,6 +43,7 @@ async function sendZPL(zplContent, ipAddress, retries = 3) {
|
|||
try {
|
||||
const result = await new Promise((resolve, reject) => {
|
||||
const client = new net.Socket();
|
||||
client.setTimeout(1000); // Establece el tiempo de espera
|
||||
|
||||
client.connect(port, ipAddress, () => {
|
||||
client.write(zplContent, () => {
|
||||
|
@ -70,11 +71,9 @@ async function sendZPL(zplContent, ipAddress, retries = 3) {
|
|||
});
|
||||
});
|
||||
|
||||
if (result === 'success') {
|
||||
return 'success';
|
||||
}
|
||||
if (result === 'success') return 'success';
|
||||
} catch (error) {
|
||||
logger.error(`Error al enviar ZPL a la impresora: ${error.message || error}`);
|
||||
if (error !== 'error') logger.error(`Error inesperado al enviar ZPL a la impresora: ${error.message || error}`);
|
||||
if (retries > 0) {
|
||||
logger.info(`Reintentando... Quedan ${retries} intentos.`);
|
||||
return sendZPL(zplContent, ipAddress, retries - 1);
|
||||
|
@ -188,7 +187,7 @@ async function processRecord(record) {
|
|||
parentPort.on('message', async msg => {
|
||||
if (msg === 'check') {
|
||||
const record = await getRecordForProcessing();
|
||||
if (record)
|
||||
if (record)
|
||||
await processRecord(record);
|
||||
else {
|
||||
// Si no hay registros, espera y vuelve a verificar
|
||||
|
|
Loading…
Reference in New Issue