Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing token in processor function #484

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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