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

Repeatable jobs, queue identical job #767

Closed
Azael05x opened this issue Sep 24, 2021 · 0 comments
Closed

Repeatable jobs, queue identical job #767

Azael05x opened this issue Sep 24, 2021 · 0 comments

Comments

@Azael05x
Copy link

Azael05x commented Sep 24, 2021

In documentation (https://docs.bullmq.io/guide/jobs/repeatable) it says:

Bull is smart enough not to add the same repeatable job if the repeat options are the same.

But in reality, it seems not to work as expected. For example here is my code of job, I want to run every hour.

export const getWorker: WorkerFactoryFn = (ctx) => {
  const hourInMs = 60 * 60 * 1000;
  const name = WorkerQueueName.NAME;
  const queue = new Queue(name, {
    connection: ctx.redis,
  });

  return {
    name,
    workers: times(1, () => new Worker<undefined, void>(name, workerHandler(name, ctx), {
      connection: ctx.redis,
      concurrency: 1,
      // The rate limiter is global, so if you have for example 10 workers
      // for one queue with the above settings, still only 10 jobs will be processed by second.
      limiter: { max: 1, duration: hourInMs },
    })),
    queueScheduler: new QueueScheduler(name, {
      connection: ctx.redis,
    }),
    queue,
    creator: {
      add: () =>
        queue.add(name, {}, {
          repeat: {
            cron: "0 * * * * *",
            jobId: name
          },
          jobId: name
        })
      ,
    },
  };
};

Checking it with documentation and source code, it seems this should be enough (don't mind multiple jobId, I was trying multiple solutions).

    /**
     * Override the job ID - by default, the job ID is a unique
     * integer, but you can use this setting to override it.
     * If you use this option, it is up to you to ensure the
     * jobId is unique. **If you attempt to add a job with an id that
     * already exists, it will not be added.**
     */
    jobId?: string;

While in reality

  await appContext.workers.workerName.creator.add();
  await appContext.workers.workerName.creator.add();
  await appContext.workers.workerName.creator.add();

creates multiple delayed jobs.

What am I missing?

@Azael05x Azael05x changed the title Repeatable jobs duplicating it self EDIT: Solved. Passed incorrect repeatable arguments Sep 24, 2021
@Azael05x Azael05x changed the title EDIT: Solved. Passed incorrect repeatable arguments Repeatable jobs, queue identical job Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant