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



61
62
63
64
65
66
67
68
69
70
# File 'lib/henchman/worker.rb', line 61

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-



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

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

#queue_nameString

Returns the name of the queue the worker of this task listens to.

Returns:

  • (String)

    the name of the queue the worker of this task listens to.



54
55
56
# File 'lib/henchman/worker.rb', line 54

def queue_name
  worker.queue_name
end

#unsubscribe!Object

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



87
88
89
# File 'lib/henchman/worker.rb', line 87

def unsubscribe!
  worker.unsubscribe!
end