3 - Use jobqueue module
OpenPaas offers many existing modules for you to use. This tip will show you how to use the jobqueue module, allowing to start background job and getting progressing informations about this job using Kue.
Prerequisite
What does this module do ?
This module provides APIs to create and manage queue job in OpenPaaS ESN.
Add jobqueue module in the dependencies of your module
var myAwesomeModule = new AwesomeModule('esn.helloworld', {
dependencies: [
...
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.jobqueue', 'jobqueue')
],
...
}
Adding a worker
Any module which import the jobqueue dependency can submit jobs in the jobqueue
The worker object to register is defined as:
dependencies('jobqueue').lib.workers.add({
name: 'contact-twitter-import',
getWorkerFunction: function() {
return yourWorkerFunction;
}
})
Calling a worker to do his job
Once registered, you can call worker job by his name and data:
dependencies('jobqueue').lib.startJob(workerName, jobName, jobData);
Job object
To get job object by his id:
dependencies('jobqueue').lib.getJobById(jobId);
You can manage your queued job in this page: http://localhost:8080/jobqueue/ui/inactive
Reference
Written on February 4, 2016
By @BTNgo