Run multiple instances of delayed_job in RAILS_ENV

I am working on a Rails application with several 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 use the delayed_job plugin (2.0.5) to control asynchrone and background work.

I would like to run multi delayed_job in 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 instance of delayed_job for the second I have this error "ERROR: there is already one or more instances of the program running"

My question is: is it not possible to run multiple instances of delayed_job in RAILS_ENV? Thanks

+7
multithreading asynchronous ruby-on-rails delayed-job
source share
2 answers

You can have multiple instances of a slow motion job if they have different process names. As mentioned in his Slim comment, you can use the -i flag to add a unique numeric identifier to the process name. Thus, the commands will look like this:

RAILS_ENV = env_name1 script / delayed_job -i 1 start

RAILS_ENV = env_name2 script / delayed_job -i 2 start

This will create two separate replaced job instances, calling them delayed_job.1 and delayed_job.2

It turns out that when you do this, you should also use the same flags when you stop them. Omitting -i 1 or -i 2 when calling stop will not stop them. Since deferred work cannot find the right appropriate process to stop.

+13
source share

Not sure if it will solve your problem, but ... I often need to run several versions of the script/server - and they do not play well with each other. The way to start them is to use different ports. eg:

 RAILS_ENV=env_name1 script/server -p 3000 RAILS_ENV=env_name2 script/server -p 3002 

Perhaps this will work on delayed_job too?

(although I would avoid port 3000, as it was a std rails port) :)

0
source share

All Articles