Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run multi delayed_job instances per RAILS_ENV

I'm working on a Rails app with multi RAILS_Env

env_name1:
  adapter:  mysql
  username: root
  password:
  host:     localhost
  database: db_name_1

env_name2:
  adapter:  mysql
  username: root
  password:
  host:     localhost
  database: db_name_2
...
..
.

And i'm using delayed_job (2.0.5) plugin to manage asynchrone and background work.

I would like start multi delayed_job per RAILS_ENV:

RAILS_ENV=env_name1 script/delayed_job start

RAILS_ENV=env_name2 script/delayed_job start
..

I noticed that I can run only one delayed_job instance for the 2nd, I have this error "ERROR: there is already one or more instance(s) of the program running"

My question : is't possible to run multi delayed_job instances per RAILS_ENV? Thanks

like image 287
Slim Tekaya Avatar asked Nov 08 '11 09:11

Slim Tekaya


1 Answers

You can have multiple instance of delayed job running as long as they have different process names. Like Slim mentioned in his comment, you can use the -i flag to add a unique numerical identifier to the process name. So the commands would look like:

RAILS_ENV=env_name1 script/delayed_job -i 1 start

RAILS_ENV=env_name2 script/delayed_job -i 2 start

This would create two seperate delayed job instances, naming them delayed_job.1 and delayed_job.2

A gotcha is that when you do this you also have to use the same flags when stopping them. Omitting the -i 1 or -i 2 when calling stop, won't stop them. As delayed job won't be able to find the correct corresponding process to stop.

like image 95
SupaIrish Avatar answered Oct 10 '22 21:10

SupaIrish