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
  • #912
Closed
Open
Issue created Apr 12, 2018 by Administrator@rootContributor

Problem with repeatable jobs

Created by: Exitialis

Hello. I need to repeat job in 10 seconds, after previous completes. How can i do it? I had tried do something like that:

index.ts:

queue.process(10, path.join(__dirname, './processors/processor.js'));
queue.add({name: 'test'}, {
    attempts: 3,
    removeOnFail: true,
    removeOnComplete: true,
    repeat: {
        cron: "*/10 * * * * *",
        endDate: new Date().getTime() + 60 * 10 * 1000
    }
});

processor.ts:

import {Job} from "bull";

export default async function(job: Job) {
    console.log('Job is running: ', job.data);

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve()
        }, 10000);
    })
}

And job is started before previous finishes. The only way I found this is to control manually and add job in the queue after previous is completed, but i need to control end time and max attempts manually.

queue.on("completed", (job: Job) => {
    job.data.count += 1;
    if (job.data.count < 5) {
        queue.add(job.data, {
            attempts: 3,
            removeOnFail: true,
            removeOnComplete: true,
        });
    }
});
Assignee
Assign to
Time tracking