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

Cannot get pollInterval to work properly #226

Open
callmephilip opened this issue Mar 30, 2017 · 1 comment
Open

Cannot get pollInterval to work properly #226

callmephilip opened this issue Mar 30, 2017 · 1 comment
Labels

Comments

@callmephilip
Copy link

I am having a hard time trying to get my job queue. Given the following setup:

const Jobs = new JobCollection("Jobs", {
  noCollectionSuffix: true
});

Meteor.startup(() => {
  Jobs.processJobs("import/media/sync", { pollInterval: 30 * 1000, payload: 5 }, (jobs, callback) => {
    _.each(jobs, job => {
       // do the job thing here
       job.done();
    });

    callback();
  });
});

// jobs are added like so:
new Job(Jobs, "import/media/sync", {}).priority("normal").save({ cancelRepeats: true });

I expect "import/media/sync" to be called every 30 seconds with 5 jobs (when available). Instead, when timing the calls, I see the worker invoked pretty much immediately after the previous worker finished processing. Am I missing something or misusing the API?

@vsivsi
Copy link
Owner

vsivsi commented Mar 30, 2017

Hi, job-collection is optimized for throughput. the pollInterval is the rate at which processJobs will ask for work when its local queue is completely empty. When the queue is not empty, it also asks for work each time a job finishes (when the callback is invoked in the worker function).

So in your case, it will request more work immediately after to invoke callback(). This is by design.

If my understanding of what you want is correct, you can achieve it by simply doing:

// Replace callback(); with:
Meteor.setTimeout(callback, 5000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants