layout | title | tip-number | tip-username | tip-username-profile | tip-tldr |
---|---|---|---|---|---|
post |
Use jobqueue module |
3 |
BTNgo |
Creating and managing job 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.
This module provides APIs to create and manage queue job in OpenPaaS ESN.
var myAwesomeModule = new AwesomeModule('esn.helloworld', {
dependencies: [
...
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.jobqueue', 'jobqueue')
],
...
}
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;
}
})
Once registered, you can call worker job by his name and data:
dependencies('jobqueue').lib.startJob(workerName, jobName, jobData);
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