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

takeLock(), ReleaseLock() functionality #108

Closed
adikaladik opened this issue Jun 6, 2019 · 4 comments
Closed

takeLock(), ReleaseLock() functionality #108

adikaladik opened this issue Jun 6, 2019 · 4 comments
Labels
question Further information is requested

Comments

@adikaladik
Copy link

Since I'm going to use a lot of job consumers which will work in parallel I found job has to methods:

/**
 * Releases the lock on the job. Only locks owned by the queue instance can be released.
 */
releaseLock(): Promise<void>;

/**
 * Takes a lock for this job so that no other queue worker can process it at the same time.
 */
takeLock(): Promise<number | false>;

Why I try to use that in my code, job fails with an erorr: '["Error: Missing lock for job 4 finished'

 @QueueProcess({ name: 'integration' })
  execute(job: Job<number>, callback: DoneCallback) {
    job.takeLock();
    this.logger.log(` start processing : ${job.id}`);
    this.userIntegrationService.processUserIntegrations(job.data).then(result => {
      job.releaseLock();
      callback(null, result);
    });
  }

Maybe I have a wrong understanding of that functuinality, but could someone advice what I do worng? Thanks!

@fwoelffel
Copy link
Contributor

Hi @adikaladik

takeLock and releaseLock both return Promise. You might have to await those calls:

 @QueueProcess({ name: 'integration' })
  async execute(job: Job<number>, callback: DoneCallback) {
    await job.takeLock();
    this.logger.log(` start processing : ${job.id}`);
    this.userIntegrationService.processUserIntegrations(job.data).then(async (result) => {
      await job.releaseLock();
      callback(null, result);
    });
  }

@fwoelffel fwoelffel added the question Further information is requested label Jun 6, 2019
@fwoelffel fwoelffel changed the title [Question] takeLock(), ReleaseLock() functionality takeLock(), ReleaseLock() functionality Jun 6, 2019
@adikaladik
Copy link
Author

Hi, @fwoelffel are there any possible options which cause an error? When I added await to those calls new error happened:

Missing lock for job 3 delayed

@fwoelffel fwoelffel reopened this Jul 4, 2019
@fwoelffel
Copy link
Contributor

Hi @adikaladik 👋
Could you provide me a repository reproducing your error? Have you checked Bull's issue tracker for a similar error? IMO that's not related to nest-bull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants