Rails custom environment Resque.enqueue does not create jobs

筅森魡賤 提交于 2019-12-25 03:25:31

问题


I'm using Resque for a couple of asynchronous jobs. I've set up a custom environment integration which is a clone of my production environment. However, my Resque jobs do not get added to Redis in my integration environment.

For example, if I run the following:

$ RAILS_ENV=production rails console
> Resque.enqueue(MyLovelyJob, 1)

I will see the job appear in resque-web.

But, if I run the following:

$ RAILS_ENV=integration rails console
> Resque.enqueue(MyLovelyJob, 1)

The job does not appear in resque-web.

Clearly I'm missing some kind of configuration, I'm pulling my hair out trying to work out what it is.


回答1:


few expectations first.

You have a config/resque_config.rb or similar like:

require 'rubygems'

require 'resque' # include resque so we can configure it
require 'resque/server'
require 'resque_scheduler'
require 'resque_scheduler/server'
require 'yaml'

Resque.redis.namespace = "resque:api"

rails_root = ENV['APP_ROOT'] || (File.dirname(__FILE__) + '/..')
# require File.expand_path(File.join(rails_root,"lib","extensions","resque","worker.rb"))

rails_env = RAILS_ENV if defined? RAILS_ENV
rails_env ||= ( ENV['RAILS_ENV'] || 'development' )

resque_config = YAML.load_file(File.join(rails_root, 'config/resque.yml'))
Resque.redis = resque_config[rails_env]

# IN THIS ORDER
Resque::Scheduler.dynamic = true
Resque.schedule = YAML.load_file(File.join(rails_root, 'config/resque_schedule.yml')) # load the schedule

and a config/resque.yml or similar like:

development: localhost:6379
test: localhost:6379
integration: localhost:6379
staging: localhost:6379
production: localhost:6379

The integration would either be on / communicate with a different server or use a different port. Then you'd have it run it's own Redis server so that the 2 aren't overlapping. I presume you didn't want production and integration queueing things to the same place?




回答2:


This is what I did to fix the problem:

I created config/initializers/resque.rb with the following content:

rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'

resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]

I also created config/resque.yml with the following content (obviously these should be set to whatever is appropriate):

development: localhost:6379
test: localhost:6379
integration: localhost:6379
staging: localhost:6379
production: localhost:6379


来源:https://stackoverflow.com/questions/11973967/rails-custom-environment-resque-enqueue-does-not-create-jobs

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