Class: DisqueJockey::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/disque_jockey/broker.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodes = ["127.0.0.1:7711"], *args) ⇒ Broker

Returns a new instance of Broker.



5
6
7
# File 'lib/disque_jockey/broker.rb', line 5

def initialize(nodes = ["127.0.0.1:7711"], *args)
  @client = Disque.new(nodes, *args)
end

Instance Method Details

#acknowledge(job_id) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/disque_jockey/broker.rb', line 14

def acknowledge(job_id)
  response = @client.call('ACKJOB', job_id)
  # If there is an error acking the job the Disque client 
  # *returns* an error object but doesn't raise it, 
  # so we raise it here ourselves.
  response.is_a?(RuntimeError) ? raise(response) : true
end

#fetch_message_from(queue) ⇒ Object



9
10
11
12
# File 'lib/disque_jockey/broker.rb', line 9

def fetch_message_from(queue)
  # fetch returns an array of jobs, but we just want the first one
  @client.fetch(from: [queue]).first
end