Alpha
Alpha

Reputation: 682

How do you start resque to use Resque.redis.namespace?

Using resque, I would like to specify a namespace and be able to see the workers in resque-web

The resque rake task is started this way:

COUNT=5 QUEUE=* RESQUE_NAMESPACE="resque:myapp" rake environment resque:workers

namespace is specified in config/initializers/resque.rb

Resque.redis.namespace = "resque:myapp"

Resque-web show on the UI the correct namespace but 0 workers are visible.

If I don't specify any namespace, everything is working ok.

A very similar question has been asked. How do you configure resque-web to use Resque.redis.namespace?, but it doesn't answer my question.

Any, clue or help appreciated.

Upvotes: 2

Views: 4025

Answers (2)

Schneems
Schneems

Reputation: 15828

Make sure you're setting this after you set your redis

ENV["OPENREDIS_URL"] ||= "redis://127.0.0.1:6379"
uri = URI.parse(ENV["OPENREDIS_URL"])

Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Rails.logger.info('Connected to Redis')
RESQUE_NAMESPACE = :my_namespace
Resque.redis.namespace = RESQUE_NAMESPACE

If you try to set Resque.redis.namespace = before Resque.redis = it gets over-written.

Also make sure to set this in any after_fork callbacks for your webserver (unicorn/puma/etc):

on_worker_boot do
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
  end

  if defined?(Resque)
    ENV["OPENREDIS_URL"] ||= "redis://127.0.0.1:6379"
    uri = URI.parse(ENV["OPENREDIS_URL"])
    Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    Resque.redis.namespace = RESQUE_NAMESPACE
    Rails.logger.info('Connected to Redis')
  end
end

Upvotes: 0

jmonteiro
jmonteiro

Reputation: 1712

You don't need to set RESQUE_NAMESPACE when loading your Resque worker, since it will load your Rails app with the Resque.redis.namespace directive.

When starting resque-web, you should use the -N param:

  resque-web -N myapp

And it should work just fine.

P.S.: I am not confident about the colon on the namespace, try not using it.

Upvotes: 2

Related Questions