Skip to content
Grant Carthew edited this page Oct 12, 2016 · 6 revisions

Description

This FAQ document will grow as more questions come in.

How do I process multi-state complex jobs?

Like many modules on the NPM registry, rethinkdb-job-queue is a building block that you use within your application. Its primary function is to reliably process jobs in a distributed application framework. It can be used on a single server very successfully though.

If you have a complex task that has multiple states and sub tasks, the best way to handle these tasks in your application is by building the task logic into your application. If you break the high level task down into individual steps or jobs you can then rely on rethinkdb-job-queue to process those lower level jobs for you.

Here is an example of the logic required to build an application that has a complex registration process. The registration process requires three sub-tasks to be performed to complete the workflow as follows:

  • Send registration activation email.
  • Register user with third party service provider.
  • Send confirmation email.

With the above three tasks we can use rethinkdb-job-queue to manage each task by creating three distinct queues; ActivationEmail, SPRegistration, and ConfirmationEmail queues.

For the management of the higher level task you will need to build this logic into your application and use your applications database to save each state.

The application logic would go something like this;

  1. User registers on your web application.
  2. Your application saves the registration to your application database (not the job queue).
  3. In the same code that you save the registration to your database, initiate a job within the ActivationEmail queue to send an account activation email.
  4. At the completion of the ActivationEmail queue job, update the registration in your application database.
  5. Wait for the user to click the activation link.
  6. After the user activates the new account, update your registration in your application database.
  7. In the same code that you update the registration, initiate a job within the SPRegistration queue to register the new account with the third party service.
  8. After the job completes, update your registration to a completed state in your application database. Possibly as a last task, initiate a job in Q3 to send a congratulations email or something similar. In the steps above, the state of the high level task is managed in your application database, not in the job queue.

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally