Righto - But is there an internal cron or cron like job that repeats itself every so often?
Meteor setTimeout and setInterval - both are using fibers so the performance is believed to be really good.
Package coming soon… some last minute adjustments popped up
Cool!
Looking to implement it now actually - because the syncedCron I’ve been relying on I suspect is causing memory leaks.
Is the API for V2 going to remain unchanged (determines whether I update now or wait the few till it’s out).
No guarantees - but it hasn’t changed much since v1, and I do not think it will change much in the future.
Here it is folks
What’s new
- a more scalable re-write of the package with es6 modules
- fine tuned control over how jobs run and their state
- type safety for package API
- more options to schedule jobs, etc
- more
Heads up: there’s a new in-app dev tool
See more here:
Hi.
This is great package. I just starred both your atmosphere and github pages.
With that said, I implemented this package but would like to change the polling interval to every six hours. I read the docs but am having trouble implementing
// Jobs.configure({
// timer: 21600 * 1000
// });
The code breaks when I include it with the Jobs.register and Jobs.run.
If you can provide insight on the best way to configure the polling interval it would be appreciated.
Try interval
instead of timer
Thanks for the follow-up. I tested it at a shorter interval and it worked!
Dear Msavin,
thanks for the great package ! Some questions :
- Jobs should be wrtten on server side ?
- Do you think it is suitable to use with my problem :
I have a collection with a particular field “end_time” which is a timestamp. I would like to find the best way to trigger an action while this timestamps passes the now() time.
Can steve jobs act depending on a timestamp in a collection ?
or I have to make a job with an interval that runs through the collection (every minute ? 10 minutes ?) and check if timestamp is passed ? Is is ressource consuming process ?
Thanks for your help !
It runs the jobs based on the time you specify. Here’s one way to do it:
Jobs.run("sendEmail", "Ivo", "me@ivo.com", {
date: function () {
return date;
}
})
You can also stack it with the in
and on
operators:
Jobs.run("sendEmail", "Ivo", "me@ivo.com", {
date: function () {
return date;
},
in: {
minutes: 10
}
})
The jobs cannot be set to run repeatedly, but you could write a job that would create a new job after it finishes. In whatever the case, the resources used should be negligible.
So each time I create one item in my collection I could set up a job to end “in” the duration time ? And therefor would not have to loop on anything ? sounds great.
You did not mention if code should be on server, client or both side ?
Thanks again !
The package is for server only - and you only deal with it’s API - it does the MongoDB stuff on its own. Check out the documentation and wiki, it should help you get a better understanding of it.
Hey Max,
starting using your package, seems great but I don’t understand something. I have the following code (combining it with collections hooks) :
Jobs.register({
"logtransa": function () {
console.log("BADABOUM");
return
}
});
Transactions.after.insert(function (doc) {
Jobs.run("logtransa", {
in: {
minute: 0.1,
},
});
});
What works : after an insert, it takes 6 seconds before jobs is started and I see “BADABOUM” in server console.
What doesn’t work (or at least not as i expected) : Jobs is running continously, the function is called hundreds of time until maximum stack exceeded and server shuts down
Didn’t find in the doc why, or how to call it only once. Did i miss the point ? For me the whole point was to call the function once, not to have it run continously.
— Actually jobs starting after server restart and 6 seconds… not even after insert
Thanks for reply,
Regards.
In the new version, jobs have to marked completed (whereas before, it would happen automatically).
Try this instead:
Jobs.register({
"logtransa": function () {
console.log("BADABOUM");
this.success(); // <------------------
return;
}
});
You can use this.success()
to mark the job complete, this.failure()
to have it run on a server restart, or this.reschedule()
to postpone it to a later time.
How to run the job, for every minute?
Jobs.register({
testjob: function () {
log.info("calling test ");
this.success(“sucess”);
return;
}
});
// schedule the job
Jobs.run(“testjob”,{
in:{
minute: 1
}
});
I tried like above, but it’s not working for me.I want to run the jobs for every minute and every day.Could you please help me how to configure the jobs to run for every minute and every day.
Hello @msavin ! Great package !
Going back on this idea, is there any plans on handing off jobs to other processes ?
We have 2 processes launched on a multi-core server and we want 1 process to handle the HTTP and the other to process heavy tasks.
Thanks !
There is one way to re-run jobs:
Jobs.register({
"jobName": function () {
doSomething()
this.reschedule({
in: {
minutes: 5
}
})
}
})
That job would run when its time comes, and as part of that, it reschedule itself.
It’s not ideal, however. The history
field in each job document keeps track of each time the document runs. It could get pretty big if you are scheduling it to run frequently. Additionally, you would have to “kickstart” the job to run the first time.
The way it would work here is, you would create two queues with Jobs.register
, and add jobs as you wish. The package will only run those jobs on one server at a time.
Do you wish to run one queue on one server and the other queue on another server? Any particular reason?
Thanks for your reply.
If I know which server is the one handling HTTP (front) and which is the one for heavy tasks (worker), I can set an activityDelay on the front server right ? And this would let the worker take the jobs as they come.
Yes my reason for this, are 100% CPU spikes that can last several seconds/minutes due to a lot of tasks to perform. So I wan to off-load the heavy tasks to the hidden process.
I did not quite get this
you would create two queues with Jobs.register, and add jobs as you wish. The package will only run those jobs on one server at a time
How is it done ?