Class: Ruote::Resque::Receiver

Inherits:
Ruote::Receiver
  • Object
show all
Defined in:
lib/ruote/resque/receiver.rb

Overview

The receiver will poll the reply_queue in Resque, waiting for reply jobs. It does so in a new thread.

By default it polls the reply_queue every 5 seconds, but this is configurable via the interval configuration option. See Ruote::Resque.

You should launch the Receiver as soon as your engine is set up.

Examples:

Running a ruote-resque Receiver

Ruote::Resque::Receiver.new(dashboard)

Overriding the handle_error method for custom exception handling

class Ruote::Resque::Receiver
  def handle_error(e)
    MyErrorHandler.handle(e)
  end
end

Ruote::Resque::Receiver.new(dashboard)

Instance Method Summary collapse

Constructor Details

#initialize(cwes, options = {}) ⇒ Receiver

Retunrs a new Receiver instance and spawns a worker thread.

Parameters:

  • cwes (Ruote::Dashboard)

    Accepts context, worker, engine or storage

  • options (Hash) (defaults to: {})

    Passed on to Ruote, currently unused.



41
42
43
44
# File 'lib/ruote/resque/receiver.rb', line 41

def initialize(cwes, options = {})
  super
  @listener = listen
end

Instance Method Details

#handle_error(e) ⇒ void

This method returns an undefined value.

Called when an error is raised during the poll/reserve/process flow of the Receiver. You should override this method for custom error handling. By default it just logs the exception.

Parameters:

  • e (Exception)


57
58
59
# File 'lib/ruote/resque/receiver.rb', line 57

def handle_error(e)
  Ruote::Resque.logger.error(e)
end

#shutdownvoid

This method returns an undefined value.

Stops the worker thread.



48
49
50
# File 'lib/ruote/resque/receiver.rb', line 48

def shutdown
  @listener.kill
end