librelist archives

« back to archive

Uninitialized Constant in Resque Worker

Uninitialized Constant in Resque Worker

From:
tim pletcher
Date:
2011-11-21 @ 15:35
i have a resque worker that processes inbound api messages from a rabbitmq
server. i have an initializer that fires up the AMQP connection, sets up
two channels (inbound and outbound) and then subscribes the application to
the inbound queue to grab the api messages, the enqueues them to resque.
that all works great.

where i am running into an issue is that the out bound channel in the
intializer is set up as a constant. i am trying to call that constant from
inside the resque worker to set up the processing of the outbound api
processing status message. here's the method in the worker:

-----------------------------------------
def self.publish_api_response_message(outbound_queue, outbound_message)

       outbound_exchange = OUTBOUND_CHANNEL.direct('outbound', :durable =>
true)
         OUTBOUND_CHANNEL.on_error do |ch, close|
           puts "Handling channel-level error"
           connection.close
         end
         OUTBOUND_CHANNEL.queue(outbound_queue, :durable => true,
:arguments => {'x-ha-policy' => 'all'}) do |queue, declare_ok|
           queue.bind(outbound_exchange, :routing_key =>
'#{outbound_queue}')
           puts "Publishing API Response Message"
           outbound_exchange.publish(outbound_message)
           puts "API REsponse Message Published"
          end
  end
--------------------------------------------------------------------------------

the uninitialized constant is the OUTBOUND_CHANNEL which is declared in the
initializer....the channel declare in the initializer is confirmed
successful via the declare_ok method that is provided by the AMQP gem, and
written to the log file so i know the channel is being successfully pinned
up.

i use heroku for production and so my resque rake task looks like this:
----------------------------------------------------------------------
require 'resque/tasks'

 case Rails.env
   when 'production','staging','sandbox'
    task "resque:setup" => :environment do
      ENV['QUEUE'] = '*'
      Resque.before_fork = Proc.new {
ActiveRecord::Base.establish_connection }
    end
      desc "Alias for resque:work (To run workers on Heroku)"
      task "jobs:work" => "resque:work"

  else
      task "resque:setup" => :environment do
        Resque.before_fork = Proc.new {
ActiveRecord::Base.establish_connection }

      end
 end
----------------------------------------------------------------------------

any guidance on this much appreciated....