0

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.

2 Answers2

0

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?

TomDunning
  • 4,829
  • 1
  • 26
  • 33
0

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