Class: Henchman::Worker::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/henchman/worker.rb

Overview

The handling of an incoming message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, headers, message) ⇒ Task

Parameters:



45
46
47
48
49
# File 'lib/henchman/worker.rb', line 45

def initialize(worker, headers, message)
  @worker = worker
  @headers = headers
  @message = message
end

Instance Attribute Details

#exceptionObject

Exception

any Exception this Henchman::Worker::Task has fallen victim to.



31
32
33
# File 'lib/henchman/worker.rb', line 31

def exception
  @exception
end

#headersObject

AMQP::Header

The metadata of the message.



17
18
19
# File 'lib/henchman/worker.rb', line 17

def headers
  @headers
end

#messageObject

Object

The message itself



21
22
23
# File 'lib/henchman/worker.rb', line 21

def message
  @message
end

#resultObject

Object

the result of executing this Henchman::Worker::Task.



36
37
38
# File 'lib/henchman/worker.rb', line 36

def result
  @result
end

#workerObject

Henchman::Worker

the Henchman::Worker this Henchman::Worker::Task belongs to.



26
27
28
# File 'lib/henchman/worker.rb', line 26

def worker
  @worker
end

Instance Method Details

#callObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/henchman/worker.rb', line 54

def call
  begin
    @result = instance_eval(&(worker.block))
  rescue Exception => e
    @exception = e
    @result = instance_eval(&(Henchman.error_handler))
  ensure
    headers.ack if headers.respond_to?(:ack)
  end
end

#enqueue(queue_name, message) ⇒ Object

Enqueue something on another queue.

Parameters:

  • queue_name (String)

    the name of the queue on which to publish.

  • message (Object)

    the message to publish-



71
72
73
74
75
# File 'lib/henchman/worker.rb', line 71

def enqueue(queue_name, message)
  Fiber.new do
    Henchman.enqueue(queue_name, message)
  end.resume
end

#unsubscribe!Object

Unsubscribe the Henchman::Worker of this Henchman::Worker::Task from the queue it subscribes to.



80
81
82
# File 'lib/henchman/worker.rb', line 80

def unsubscribe!
  worker.unsubscribe!
end