Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Latest commit

 

History

History
72 lines (47 loc) · 1.66 KB

2016-2-4-use-jobqueue-module.md

File metadata and controls

72 lines (47 loc) · 1.66 KB
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.

Prerequisite

Create an OpenPaas module

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