Skip to content

Commit

Permalink
Merge pull request #19 from Kakulukian/master
Browse files Browse the repository at this point in the history
[moleculer-bull] Add job concurrency
  • Loading branch information
icebob committed Mar 18, 2018
2 parents 9ae6a91 + d863637 commit c89423c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/moleculer-bull/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ module.exports = function createService(url, queueOpts) {

if (this.schema.queues) {
_.forIn(this.schema.queues, (fn, name) => {
this.getQueue(name).process(fn.bind(this));
if(typeof fn === "function")
this.getQueue(name).process(fn.bind(this));
else
this.getQueue(name).process(fn.concurrency, fn.process.bind(this));
});
}

Expand Down
14 changes: 11 additions & 3 deletions packages/moleculer-bull/test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,28 @@ describe("Test BullService created handler", () => {
queues: {
"task.first": jest.fn(),
"task.second": jest.fn(),
"task.concurrency": {
concurrency: 100,
process(job) {
return jest.fn();
},
},
}
});

it("should be created queues", () => {
expect(service).toBeDefined();
expect(Object.keys(service.$queues).length).toBe(2);
expect(Object.keys(service.$queues).length).toBe(3);
expect(service.$queues["task.first"]).toBeDefined();
expect(service.$queues["task.second"]).toBeDefined();
expect(service.$queues["task.concurrency"]).toBeDefined();

expect(Queue).toHaveBeenCalledTimes(2);
expect(Queue).toHaveBeenCalledTimes(3);
expect(Queue).toHaveBeenCalledWith("task.first", url, opts);
expect(Queue).toHaveBeenCalledWith("task.second", url, opts);
expect(Queue).toHaveBeenCalledWith("task.concurrency", url, opts);

expect(processCB).toHaveBeenCalledTimes(2);
expect(processCB).toHaveBeenCalledTimes(3);
});

});
Expand Down

0 comments on commit c89423c

Please sign in to comment.