Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
worker.js file not processing jobs sent to it on Heroku

For some reason, this setup isn't working. All I'm trying to do is run the processing of the job not on the main thread, because it's blocking my event loop. Procfile looks like:

web: node app.js
worker: node worker.js

package.json:

{
"name": "server-testing",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm start"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "bull": "^3.22.6",
    "express": "^4.17.1",
    "throng": "^5.0.0"
  },
  "engines": {
    "node": "14.17.6"
  }
}

app.js:

const express = require('express');
const app = express();
const http = require('http').Server(app);
const Queue = require('bull');

const workQueue = new Queue('work', process.env.REDIS_URL)

app.post('/addJob', async function(request, response) {
  let job = await workQueue.add({request: request.body});
  console.log("Logging job as " + job.id)
  response.json({ id: job.id });
});

worker.js:

let throng = require('throng');
let Queue = require("bull");
let REDIS_URL = process.env.REDIS_URL
let workers = process.env.WEB_CONCURRENCY || 1;
let maxJobsPerWorker = 3;

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function start() {
  console.log("Started processing")
  let workQueue = new Queue('work', REDIS_URL);
  workQueue.process(maxJobsPerWorker, async (job) => {

    let progress = 0;

    if (Math.random() < 0.05) {
      throw new Error("This job failed!")
    }

    while (progress < 100) {
      await sleep(50);
      progress += 1;
      job.progress(progress)
    }

    return { value: "This will be stored" };
    console.log("Finished processing")
  });
}

throng({ workers, start });

Output of 'Heroku ps' command:

=== web (Free): node app.js (1)
web.1: up 2021/10/01 20:57:34 -0400 (~ 11m ago)

=== worker (Free): node worker.js (1)
worker.1: up 2021/10/01 20:57:31 -0400 (~ 11m ago)

Essentially, the console.log() statements inside the process function are never printing, indicating the jobs are never being processed. Not sure what I'm missing here...

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!