UNPKG

ihub-framework-js

Version:

Legacy version of iHub Framework written in Javascript

26 lines (23 loc) 690 B
const { CronJob } = require('cron'); const log = require('../logger'); module.exports = apm => ( new Promise((resolve) => { /* Listen to jobs in the routine abstraction */ const job = (id, action, cron, runOnInit) => { log.debug(`Loading routine ${id}`); /* eslint-disable no-new */ new CronJob(cron, () => { let trans = null; log.info(`Job for ${id} started`); if (apm) trans = apm.startTransaction(id, 'Routines'); action(() => { if (trans) trans.end(); log.info(`Job for ${id} done`); }); }, null, true, 'America/Sao_Paulo', null, runOnInit); }; resolve({ job, }); }) );