run multi delayed_job instances per RAILS_ENV

痴心易碎 提交于 2019-12-05 23:18:55

问题


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


回答1:


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.




回答2:


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) :)



来源:https://stackoverflow.com/questions/8048542/run-multi-delayed-job-instances-per-rails-env

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!