diff --git a/src/infra/cron/observer.cron.js b/src/infra/cron/observer.cron.js index e6abde7..298890b 100644 --- a/src/infra/cron/observer.cron.js +++ b/src/infra/cron/observer.cron.js @@ -5,7 +5,7 @@ loadEnv() const cron = require('node-cron') const {logError, logInfo} = require('../../shared/utils/logger') -const runWatchdog = require('../../modules/watchdog/job/job') +const {runWatchdog} = require('../../modules/watchdog/job/job.js') logInfo('[CRON] 🐶 Watchdog cron iniciado') @@ -14,8 +14,9 @@ cron.schedule('*/5 * * * *', async () => { try { await runWatchdog() - } catch (error) { - logError('[CRON] ❌ Erro no Watchdog', { error }) + } catch (error) { + logError(`[CRON] ❌ Erro no Watchdog: ${error?.message || error}`) + if (error?.stack) logError(error.stack) } }) diff --git a/src/modules/watchdog/job/job.js b/src/modules/watchdog/job/job.js index 3e562ec..52273ab 100644 --- a/src/modules/watchdog/job/job.js +++ b/src/modules/watchdog/job/job.js @@ -1,18 +1,15 @@ // src/modules/watchdog/job/job.js -const { logError, logInfo } = require('../../../shared/utils/logger') +const { logInfo } = require('../../../shared/utils/logger') const { notifyCollaborators } = require('../services/notifyCollaborators.service.js') const { notifyAdmins } = require('../services/notifyAdmins.service.js') async function runWatchdog() { - const { sentCount: sentFunc } = await notifyCollaborators({ thresholdMinutes: 31 }) - const { sentCount: sentAdm } = await notifyAdmins({ sinceMinutes: 30 }) + const { sentCount: sentFunc } = await notifyCollaborators({ thresholdMinutes: 31 }) + const { sentCount: sentAdm } = await notifyAdmins({ sinceMinutes: 30 }) - logInfo(`[WATCHDOG] [JOB] Enviadas ${sentFunc} notificacoes para colaboradores e ${sentAdm} para ADM.`) + logInfo(`[WATCHDOG] [JOB] Enviadas ${sentFunc} notificacoes para colaboradores e ${sentAdm} para ADM.`) } -runWatchdog().catch((error) => { - logError('[WATCHDOG] [JOB] Erro ao executar o job do Watchdog', error) -}) - module.exports = { runWatchdog } +