I'm trying to use delayed_job for various parts of a rails app. The problem is that if we have multiple instances of the app running, but certain jobs (processing uploads, for example) need to be run by local workers, whereas others could benefit by being run by any worker.
Does anyone have any recommendations for a good approach to having local/non-local job types?
I just read "Background Processing with delayed_job" in the latest issue of Rails Magazine and it occurred to me that you could abuse the built-in job priority system.
You can specify a minimum and maximum priority for your workers. Now if your special local-only jobs have a priority of 42 this worker will only process those jobs...
rake jobs:work RAILS_ENV=production MIN_PRIORITY=42 MAX_PRIORITY=42
whilst this worker will process everything except those special local-only jobs:
rake jobs:work RAILS_ENV=production MIN_PRIORITY=0 MAX_PRIORITY=10
This should be flexible enough to achieve what you need. However, I freely admit that I only learnt about this feature today and haven't tried it out myself so YMMV!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With