-
Notifications
You must be signed in to change notification settings - Fork 16
Complex Job
I will complete this document after the features discussed in #47 have been added.
If you have a need to process complex jobs rethinkdb-job-queue may do the job for you. To help you decide, this document will describe some of the different ways you can employ the queue. The document is broken down into the following complex job processing types:
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;
- User registers on your web application.
- Your application saves the registration to your application database (not the job queue).
- In the same code that you save the registration to your database, initiate a job within the
ActivationEmailqueue to send an account activation email. Use database transactions for reliability. - At the completion of the
ActivationEmailqueue job, update the registration state in your application database. - Wait for the user to click the activation link.
- After the user activates the new account, update the registration state in your application database.
- In the same code that you update the registration state, initiate a job within the
SPRegistrationqueue to register the new account with the third party service. Again, use database transactions for reliability. - At the completion of the
SPRegistrationqueue job, update the registration state in your application database. - In the same code that you update the registration state, initiate a job within the
ConfirmationEmailqueue to send a congratulations or confirmation email to the new user. - At the completion of the
ConfirmationEmailqueue job, update the registration state to completed in your application database.
Please see the Tutorial, Queue Constructor, Queue PubSub, Job Processing, and Queue.process documents for more detail.
- Introduction
- Tutorial
- Queue Constructor
- Queue Connection
- Queue Options
- Queue PubSub
- Queue Master
- Queue Events
- State Document
- Job Processing
- Job Options
- Job Status
- Job Retry
- Job Repeat
- Job Logging
- Job Editing
- Job Schema
- Job Name
- Complex Job
- Delayed Job
- Cancel Job
- Error Handling
- Queue.createJob
- Queue.addJob
- Queue.getJob
- Queue.findJob
- Queue.findJobByName
- Queue.containsJobByName
- Queue.cancelJob
- Queue.reanimateJob
- Queue.removeJob
- Queue.process
- Queue.review
- Queue.summary
- Queue.ready
- Queue.pause
- Queue.resume
- Queue.reset
- Queue.stop
- Queue.drop
- Queue.Job
- Queue.host
- Queue.port
- Queue.db
- Queue.name
- Queue.r
- Queue.id
- Queue.jobOptions [R/W]
- Queue.changeFeed
- Queue.master
- Queue.masterInterval
- Queue.removeFinishedJobs
- Queue.running
- Queue.concurrency [R/W]
- Queue.paused
- Queue.idle
- Event.ready
- Event.added
- Event.updated
- Event.active
- Event.processing
- Event.progress
- Event.log
- Event.pausing
- Event.paused
- Event.resumed
- Event.completed
- Event.cancelled
- Event.failed
- Event.terminated
- Event.reanimated
- Event.removed
- Event.idle
- Event.reset
- Event.error
- Event.reviewed
- Event.detached
- Event.stopping
- Event.stopped
- Event.dropped
- Job.setName
- Job.setPriority
- Job.setTimeout
- Job.setDateEnable
- Job.setRetryMax
- Job.setRetryDelay
- Job.setRepeat
- Job.setRepeatDelay
- Job.updateProgress
- Job.update
- Job.getCleanCopy
- Job.addLog
- Job.getLastLog