We often have background jobs in our app. E.g. sending an email when certain collections change. Or to do aggregations, prepare exports, etc.
This is easy with meteor:
Companies.find().observe({
added() {
// send email, trigger some aggregation, ....
}
});
But once you are on a multi-process-environment, you can no longer guarantee, that this work is done multiple times (one per process).
We solved this by running a dedicated meteor process, that has a specify env-variable set:
if (Meteor.isDevelopment || process.env.BACKGROUND_JOBS_ENABLED) {
jobs(); // this start all observers, etc. should only run on one instance
}
because these jobs might be cpu-bound, this process does not answer web-requests and is only for this background jobs. This guarantees that no long-running job blocks client requests.
This is a really easy setup, altough it has some overhead (most code is not used in the background-process).
However on galaxy, you don’t have influence on that. so my question is how you should deal with this on galaxy.