Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startScheduler (callback) {
let self = this
// check if the scheduler are enabled
if (self.api.config.tasks.scheduler !== true) { return callback() }
// get the scheduler logger
self.schedulerLogging = self.api.config.tasks.schedulerLogging
// create a new scheduler instance
let Scheduler = NR.scheduler
self.scheduler = new Scheduler({ connection: self.connectionDetails, timeout: self.api.config.tasks.timeout })
// define the handler for the on error event
self.scheduler.on('error', error => self.api.log(error, 'error', '[api.resque.scheduler]'))
// start the scheduler
self.scheduler.connect(() => {
// define some handlers to the scheduler events
self.scheduler.on('start', () => self.api.log('resque scheduler started', self.schedulerLogging.start))
self.scheduler.on('end', () => self.api.log('resque scheduler ended', self.schedulerLogging.end))
self.scheduler.on('poll', () => self.api.log('resque scheduler polling', self.schedulerLogging.poll))
self.scheduler.on('working_timestamp', timestamp => self.api.log(`resque scheduler working timestamp ${timestamp}`, self.schedulerLogging.working_timestamp))
self.scheduler.on('transferred_job', (timestamp, job) => self.api.log(`resque scheduler enqueuing job ${timestamp}`, self.schedulerLogging.transferred_job, job))
// start the scheduler
self.scheduler.start()