Skip to content

Commit

Permalink
feat(worker): passing token in processor function
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Apr 21, 2021
1 parent 0faf083 commit 2249724
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class Worker<

lockExtender();
try {
const result = await this.processFn(job);
const result = await this.processFn(job, token);
return await handleCompleted(result);
} catch (err) {
return handleFailed(err);
Expand Down
1 change: 1 addition & 0 deletions src/commands/getState-7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'delayed'
'active'
'waiting'
'waiting-children'
'unknown'
]]
if redis.call("ZSCORE", KEYS[1], ARGV[1]) ~= false then
Expand Down
1 change: 1 addition & 0 deletions src/commands/getStateV2-7.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'delayed'
'active'
'waiting'
'waiting-children'
'unknown'
]]
if redis.call("ZSCORE", KEYS[1], ARGV[1]) ~= false then
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/worker-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AdvancedOptions, QueueBaseOptions, RateLimiterOptions } from './';
*/
export type Processor<T = any, R = any, N extends string = string> = (
job: Job<T, R, N>,
token: string,
) => Promise<R>;

export interface WorkerOptions extends QueueBaseOptions {
Expand Down
3 changes: 2 additions & 1 deletion src/test/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('workers', function() {

describe('auto job removal', () => {
it('should remove job after completed if removeOnComplete', async () => {
const worker = new Worker(queueName, async job => {
const worker = new Worker(queueName, async (job, token) => {
expect(token).to.be.string;
expect(job.data.foo).to.be.equal('bar');
});
await worker.waitUntilReady();
Expand Down

0 comments on commit 2249724

Please sign in to comment.