Slim Tekaya
Slim Tekaya

Reputation: 347

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

Upvotes: 7

Views: 3507

Answers (2)

SupaIrish
SupaIrish

Reputation: 766

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.

Upvotes: 14

Taryn East
Taryn East

Reputation: 27747

Not sure if it'll solve your problem but... I often need to run multiple versions of script/server - and those don't play nice with each other either. The way to get them running is to use different ports. eg:

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

Perhaps this'll work for delayed_job too?

(though I'd avoid port 3000 as it's the std rails port) :)

Upvotes: 0

Related Questions