- db.Job.listWithLimit(limit, state, (err, jobs) => {
- this.enqueueJobs(err, jobsQueue, jobs)
-
- forever(
- next => {
- if (jobsQueue.length() !== 0) {
- // Finish processing the queue first
- return setTimeout(next, JOBS_FETCHING_INTERVAL)
- }
-
- const state = JOB_STATES.PENDING
- db.Job.listWithLimit(limit, state, (err, jobs) => {
- if (err) {
- logger.error('Cannot list pending jobs.', { error: err })
- } else {
- jobs.forEach(job => {
- jobsQueue.push(job)
- })
+ db.Job.listWithLimit(limit, state)
+ .then(jobs => {
+ this.enqueueJobs(jobsQueue, jobs)
+
+ forever(
+ next => {
+ if (jobsQueue.length() !== 0) {
+ // Finish processing the queue first
+ return setTimeout(next, JOBS_FETCHING_INTERVAL)