Search code examples
ruby-on-railsruby-on-rails-4delayed-job

Running delayed_job for different environments on the same server


We have a setup where two different environments (staging and training, say) of the same Rails app run on a single server. We are implementing a feature that relies on the delayed_job gem.

We've discovered that it's not possible to run delayed_job start for both environments, as the second one sees the first instance and thinks it's already running. However, the -i command switch (staging\bin\delayed_job -i staging start and training\bin\delayed_job -i training start) lets two instances coexist; but it looks like this switch is designed to start multiple workers for a single app (much like delayed_job -n 2 start), rather than for multiple apps.

We're not clear whether the daemons started this way will correctly process the jobs from their own apps, or whether there is any further configuration needed to make that happen. Can anyone enlighten us?


Solution

  • There are a few interesting options to note from the ./script/delayed_job --help output.

    • --pid-dir=DIR Specifies an alternate directory in which to store the process ids.
    • --log-dir=DIR Specifies an alternate directory in which to store the delayed_job log.

    Those both default to a sub-directory of the source directory, so if happen to be running out of multiple source directories, it should work fine. If for some reason that's not the case on your version, or if you are running from the same dir, with different environments, then you should set up your folders accordingly so that each have their own PID folder at the very least.

    • -p --prefix NAME String to be prefixed to worker process names

    This doesn't change the pid file names, only what you will see with ps