percolatestudio/meteor-synced-cron — pull request #13 by aaronthorp (2014-09-16 03:25:16+00:00)
Title: added autoStart, Job Ids, List and Remove Functions

Stumbled across this package as I have a project that requires a task for each service that a user adds to their account to have a worker and they can enable and disable it once it is configured. Added the following features to get this to work for my project, might be useful for others:

- `autoStart` option allows for adding a job to start any outstanding jobs that have been added.
- `add` function returns an `_id` either set by user or a `Meteor.uuid()` for the job
- `list` lists the current tasks and if they are active (removed the actual `job` and `_timer` functions from the return)
- `remove` allows you to remove by `_id` or `name` fields
- `SyncedCron.nextScheduledAtDate` can now take `_id` or `name` fields as input

Example case:
```
SyncedCron.options = {
log: true, // log debug info to the console
collectionName: 'cronHistory', // default name of the collection used to store job history,
utc: true, // use UTC for evaluating schedules (default: local time)
autoStart: true
};

var workerHandle = ServiceCollection.find({status: true}).observeChanges({
added: function(id, fields) {
console.log("Worker Added: "+ id)
SyncedCron.add({
_id: id,
name: 'Service Worker '+ id,
schedule: function(parser) {
// parser is a later.parse object
return parser.text('every 30 seconds');
},
job: function() {
Meteor.call('services/process/changes', id);
}
});
},
removed: function(id) {
console.log("Worker Removed: "+ id)
SyncedCron.remove(id);
}
});
```