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
  • #1047
Closed
Open
Issue created Sep 06, 2018 by Administrator@rootContributor

Promise result from removeRepeatable

Created by: xoryouyou

Description

When having a repeatable Job running and calling queue.removeRepeatable is just simply resolves a promise with null regardless of the removal of the job.

In the sample below I create a repeatable Job and watch on the queue for completed jobs matching the repeatable job id and try to remove the job.

When passing job.opts.repeat to removeRepeatable it removes the job as it should returning null, but just passing something wrong like {foo:"bar"} does nothing and also returns null.

It would be greate when https://github.com/OptimalBits/bull/blob/master/lib/repeatable.js#L98 would return a meaningfull result from its _this.client.RemoveRepeatable call.

Minimal, Working Test code to reproduce the issue.

test.js

var Queue = require("bull");
var path = require("path");
describe("Cron Test", () => {
  let helloQueue = undefined;

  before(done => {
    // create a worker queue in redis
    helloQueue = new Queue("hello", "redis://127.0.0.1:6379");
    // spawn a given number of workers
    helloQueue.process(1, path.resolve(".hello_module.js"));
    done();
  });

  it("should be able to have cron job running every 5s", done => {
    let jobId = undefined;

    helloQueue
      .add({ hello: "Cron Job" }, { repeat: { cron: "*/5 * * * * *" } })
      .then(job => {
        jobId = job.id.split(":")[1];

        console.log("job added", jobId);
        job.finished(result => {
          console.log("finished ", result);
        });
      });

    helloQueue.on("completed", (job, result) => {
      // filter for the cron job
      if (job.id.includes(jobId)) {
        console.log("[+][Cron  Job: " + job.id + "] Result:", result);

        console.log("[.] Removing cronjob (needs job.opts.repeat object)");
        helloQueue
          .removeRepeatable({ foo: "bar" }) // change to ".removeRepeatable(job.opts.repeat)  and it works
          .then(result => {
            console.log("[=] Cron Job removed:", result);
          })
          .catch(err => {
            console.log("[x] Failed to remove Cron job", err);
          });
      }
    });
  }).timeout(500000);

  after(done => {
    helloQueue.close();
    done();
  });
});

hello_module.js

let timeout = t => {
  return new Promise((resolve, reject) => {
    setTimeout(() => resolve(), t);
  });
};

module.exports = async job => {
  console.log(
    "[.][Worker Job:" + job.id + "] Working on: " + JSON.stringify(job.data)
  );
  await timeout(100);
  return Promise.resolve("Hello " + job.data.hello);
};

Bull version

^3.4.8

Additional information

Assignee
Assign to
Time tracking