Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bull
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 175
    • Issues 175
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 9
    • Merge requests 9
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OptimalBits
  • bull
  • Issues
  • #1200
Closed
Open
Issue created Jan 30, 2019 by Administrator@rootContributor

Clarifying repeating/canceling jobs

Created by: jmonster

Description

I had a difficult time figuring out the proper incantation to create and destroy repeatable jobs. I'm opening this issue to provide a working example for anyone else who might be googling the issues I ran into.

I ran into the following scenarios as I trial-and-errored my way to this solution.

  • a repeating job didn't fire until the repetition time (rather than immediately)
  • the job couldn't be deleted
  • only 1 job was being created (despite attempting to create 100 jobs with different data payloads)
  • jobs weren't being removed when they were done or failed

The core point of confusion seemed to be where/how to pass jobId; it needs to be passed as part of the repeatOpts object.

Correct example

const ONE_SECOND = 1000;
const ARBITRARY_INTERVAL = 3000;

const Queue = require('bull');
const myQueue = new Queue('my-queue-name',
  {
    limiter: { max: 1, duration: ONE_SECOND }, // 1 job/second
    defaultJobOptions: {
      removeOnFail: true,
      removeOnComplete: true
    }
  }
);

const someCollection = [1,2,3];
someCollection.forEach((jobId) => {
  const repeatOpts = { jobId, every: ARBITRARY_INTERVAL }; // note that `jobId` is part of the `repeat` options

  // adding to the queue
  myQueue.add({ arbitraryDataKey: 123 }, { repeat: repeatOpts }); // an object with a `repeat` key

  // removing from the queue
  myQueue.removeRepeatable(repeatOpts); // the repeatOpts are passed directly; not an object with a `repeat` key
});
Assignee
Assign to
Time tracking