'use strict';

// Cargar configuración mínima del worker (solo dotenv + dataDir; sin selectores ni lógica de negocio)
require('./workerConfig');

const WorkerRuntime = require('./workerRuntime');

const worker = new WorkerRuntime();

process.on('SIGINT', () => {
    console.log('\n[WORKER] Señal de interrupción recibida, deteniendo...');
    worker.stop();
    setTimeout(() => process.exit(0), 2000);
});

process.on('SIGTERM', () => {
    worker.stop();
    setTimeout(() => process.exit(0), 2000);
});

worker.runLoop().catch(err => {
    console.error('[WORKER] Error fatal:', err.message);
    process.exit(1);
});
