-
Notifications
You must be signed in to change notification settings - Fork 35
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
Find if there is a pending instance of a given job #58
Comments
I agree with this. Here's a few helper functions I've written for myself: Jobs.findAndDelete = function(jobName, param) {
const query = {};
if (jobName) query.name = jobName;
if (param) query.arguments = param;
const count = Jobs.collection.remove(query);
//console.log("Jobs.findAndDelete", jobName, param, count);
return count;
}
Jobs.count = function(jobName, param) {
const query = {};
if (jobName) query.name = jobName;
if (param) query.arguments = param;
const count = Jobs.collection.find(query).count();
//console.log("Jobs.countWithName", jobName, param, count);
return count;
}
Jobs.runOnce = function(jobName) {
if (!Jobs.count(jobName)) Jobs.run(jobName);
} It would be great if similar or better functions could be built-in. My use cases include:
Note that Jobs.count and Jobs.findAndDelete can only search for one parameter - this is fine for my needs so far but better functions should be able to match multiple parameters with AND. Plus Jobs.runOnce doesn't take any extra parameters or options. |
Yes, I think something like this would be helpful - although since I am brand new to this package, I may be missing something obvious. I want the ability for a specific jobs to be scheduled/removed from a given queue, but I don't see how to get the jobId without querying the Jobs collection with parameters as @wildhart is doing. Or should register these jobs with some unique ID in the Job name and stop/start their queues using their names? In my use case, that would create a lot of different queues (all with slightly different names) all doing pretty much the same thing - so I don't think that is the right approach. |
I've recently ran into this issue while making https://www.hndetox.com, and here's what I figured.
A copy-paste from the documentation with more info on these fields:
These two will run a query before inserting the job. You can see their code in |
For a couple use cases (detailed below), I would need to find if there exists pending instances of a given job.
Unless I'm missing something, it seems the current API offers no way of doing that ? (aside from using internal methods or querying the jobs collection directly, which might break on subsequent package versions)
My use cases :
Setting up "cron tasks" on startup :
With the new features in 3.0 I can have jobs that reschedule (well, replicate()) themselves at a later date after completion.
On app startup I register the callbacks, and then need to schedule the 1st run - but only if there is no pending run already scheduled from a previous startup
(Think of a deploy that adds a new cron task that didn't exist before)
Debouncing execution of a task between web backends :
We host our app on several (well, 2 at the moment) servers behind HAProxy.
There are some expensive tasks, triggered by user frontend action received by DDP method, or by external services through an HTTP route, that we would like to debounce. That debounce needs to cover calls triggered by any of the servers.
I was thinking of doing that by scheduling a job for execution a couple seconds later - but only if an instance isn't already pending.
The text was updated successfully, but these errors were encountered: