Code Monkey home page Code Monkey logo

Comments (1)

rschmukler avatar rschmukler commented on May 13, 2024

Not calling done would still allow multiple jobs to be run at once, specifically on per-job concurrency, or entire queue concurrency. A job will be considered "finished" when you call done(). If you do not take done as an argument, then it will be marked as done when the function reaches the end. You shouldn't take done as an argument if you aren't going to call it, as then agenda will

If you want agenda to only ever run one job at a time, you can do the following:

agenda.maxConcurrency(1);

This tells agenda to only ever allow one job to be processing at once.

If you want to specify it for a specific job, you can do:

agenda.define('some job', {concurrency: 1}, function(job, done) {
});

So, for example:

agenda.maxConcurrency(3);

var start = new Date();

agenda.define('longer job', {}, function(job, done) {
   setTimeout(function() {
      var now = new Date();
      console.log("Hello one - %d ms later", now - start);
      done();
   }, 1700);
});

agenda.define('long job', {concurrency: 1}, function(job, done) {
   setTimeout(function() {
      var now = new Date();
      console.log("Hello two - %d ms later", now - start);
      done();
   }, 1000);
});

agenda.now('longer job');
agenda.now('longer job');
agenda.now('long job');
agenda.now('long job');
agenda.now('longer job');
agenda.start();

Results in the following:

Hello two - 1026 ms later
Hello one - 1724 ms later
Hello one - 1725 ms later
Hello two - 2028 ms later
Hello one - 3425 ms later

As for the callback signature:

job is a Job instance. See here for documentation.

done is a function which lets the agenda know that the job finished, and tells it to queue up the next job, given the current state of running jobs and concurrency limitations.

Hope this helps

from agenda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.