Open gbhrdt opened 7 years ago
Hi, can you provide more information about how to reproduce this error?
Specifically, what do you mean by:
... a job with the dependents option set to false.
Can you please share a working minimal reproduction (a working Meteor project that does nothing but create a JobCollection and then create a job or jobs that trigger this error).
Just from your minimal description and the included stack trace I can't easily intuit the code that will reproduce this error.
Thanks!
Hi @vsivsi
jus see this example:
import { Meteor } from 'meteor/meteor';
import { _ } from 'lodash';
const PushJobs = new JobCollection('pushJobs');
// process 'removeOldJobs'
PushJobs.processJobs('removeOldJobs', { concurrency: 1, workTimeout: 20000 }, (job, cb) => {
const oldJobsTime = new Date((new Date()).getTime() - 30 * 1000); // 30 secs
const updateCountJobs = PushJobs.find({ type: 'updateNotificationCounts', status: { $in: PushJobs.jobStatusCancellable }, updated: { $lte: oldJobsTime, $exists: true } }, { fields: { _id: 1 }
}).fetch();
if (PushJobs.cancelJobs(_.map(updateCountJobs, '_id'), {
dependents: false // prevent checking for dependent jobs that don't exist anyway
})) {
PushJobs.removeJobs(_.map(updateCountJobs, '_id'));
}
job.done();
cb();
});
// process 'updateNotificationCounts' dummy job
PushJobs.processJobs('updateNotificationCounts', { concurrency: 1, workTimeout: 20000 }, (job, cb) => {
// do nothing
job.done();
cb();
});
Meteor.startup(() => {
// start the job that removes the old jobs
new Job(PushJobs, 'removeOldJobs', {})
.priority('normal')
.repeat({
schedule: PushJobs.later.parse.recur().every().minute()
})
.save({ cancelRepeats: true });
// fill the DB with dummy jobs to be removed
Meteor.setInterval(() => {
new Job(PushJobs, 'updateNotificationCounts', {})
.priority('normal')
.save();
}, 5000);
});
This is what I mean by a job dependents option set to false
.
By doing that, I can reproduce the error easily, my jobs don't have any dependencies and meteor-job-collection
seems to query mongoDB with an empty array. Just leave the example running for about one minute and the error will show.
Okay, thanks for that. I see the bug, weird that no one has ever encountered this before. Probably because cancelling dependent jobs is both the default behavior, and the normally correct thing to do. (Why would you want dependent jobs to remain waiting forever after their antecedent is cancelled? )
Anyway, I'll fix this and it will be in the next release whenever that is. In the meantime, just don't do this (set dependents: false
) and you'll get no error.
Thanks for the bug report!
Fixed on master
branch. Thanks again! I'll leave this open until I publish a release with this fix.
Thanks for the fix!
We were creating and also cancelling many jobs at once and we detected a very high CPU usage at our mongo DB. This was probably due to the dependency check queries, which are executed every time when cancelling the job. if you don't use job dependencies, I would recommend anyone to disable that option, if you have many jobs running, because of performance reasons.
Oh, that's a good tip! Thx.
I am running
job.cancel()
inside a running job. Getting this Mongo exception when trying to cancel a job with thedependents
option set tofalse
: