Reputation: 33
I want to add function which will run in a separate thread once every few seconds on server.
I read This post and find a lot of CRON packages that can help me with that, but I do not know exactly where they API need to be added in code, it's probably because I do not quite understand how they work with Meteor.
I think my question is a little blunt, but maybe someone tell me where i can put CRON packages functionality in code ?
Upvotes: 1
Views: 1343
Reputation: 252
Now that SyncedCron is deprecated, I decided to offer a new background jobs package called Steve Jobs. It's production tested and easy to grasp for Meteor developers.
Upvotes: 0
Reputation: 2252
I'm using https://atmospherejs.com/percolate/synced-cron as an example of a cron job runner.
You would run this package's code on the server (See: https://github.com/percolatestudio/meteor-synced-cron/blob/master/package.js#L13).
For example, you could schedule a background task after calling a Meteor method:
Meteor.methods({
doCron: function() {
SyncedCron.add({
name: 'Crunch some important numbers for the marketing department',
schedule: function(parser) {
// parser is a later.parse object
return parser.text('every 2 hours');
},
job: function() {
var numbersCrunched = CrushSomeNumbers();
return numbersCrunched;
}
});
}
});
// Somewhere in your code you need this to start processing jobs. Also on server.
Meteor.startup(function () {
// code to run on server at startup
SyncedCron.start();
});
Upvotes: 3