Skip to content

ddurgesh28/node-workers-example

 
 

Repository files navigation

Background Jobs in Node.js with Redis

Redis-backed background worker example using OptimalBits/bull and throng.

Application Screenshot

Deploy

Installing Local Dependencies

$ brew install redis
$ brew services start redis

Getting Started

  1. npm install
  2. npm start
  3. http://localhost:5000

Deploying

$ git clone https://github.com/ddurgesh28/node-workers-example
$ cd node-workers-example

$ heroku apps:create <your-app-name>
$ heroku apps:transfer heroku-india-workshop --app <your-app-name>
$ heroku addons:create heroku-redis
$ git push heroku master
$ heroku ps:scale worker=1
$ heroku open

Application Overview

The application is comprised of two process:

  • web - An Express server that serves the frontend assets, accepts new background jobs, and reports on the status us existing jobs
  • worker - A small node process that listens for and executes incoming jobs

Because these are separate processes, they can be scaled independently based on specific application needs. Read the Process Model article for a more in-depth understanding of Heroku’s process model.

The web process serves the index.html and client.js files which implement a simplified example of a frontend interface that kicks off new jobs and checks in on them.

About

A simple example of using Redis to coordinate a worker process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 75.4%
  • HTML 24.6%