Class: Woodhouse::Runners::HotBunniesRunner

Inherits:
Woodhouse::Runner show all
Defined in:
lib/woodhouse/runners/hot_bunnies_runner.rb

Overview

A Runner implementation that uses hot_bunnies, a JRuby AMQP client using the Java client for RabbitMQ. This class can be loaded if hot_bunnies is not available, but it will fail upon initialization. If you want to use this runner (it’s currently the only one that works very well), make sure to add

gem 'hot_bunnies'

to your Gemfile. This runner will automatically be used in JRuby.

Instance Method Summary collapse

Methods inherited from Woodhouse::Runner

#initialize

Constructor Details

This class inherits a constructor from Woodhouse::Runner

Instance Method Details

#bail_out(err) ⇒ Object

Raises:



63
64
65
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 63

def bail_out(err)
  raise Woodhouse::BailOut, "#{err.class}: #{err.message}"
end

#spin_downObject



59
60
61
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 59

def spin_down
  signal :spin_down
end

#subscribeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 21

def subscribe
  client = HotBunnies.connect(@config.server_info)
  channel = client.create_channel
  channel.prefetch = 1
  queue = channel.queue(@worker.queue_name)
  exchange = channel.exchange(@worker.exchange_name, :type => :headers)
  queue.bind(exchange, :arguments => @worker.criteria.amqp_headers)
  worker = Celluloid.current_actor
  queue.subscribe(:ack => true).each(:blocking => false) do |headers, payload|
    begin
      job = make_job(headers, payload)
      if can_service_job?(job)
        if service_job(job)
          headers.ack
        else
          headers.reject
        end
      else
        @config.logger.error("Cannot service job #{job.describe} in queue for #{@worker.describe}")
        headers.reject
      end
    rescue => err
      begin
        @config.logger.error("Error bubbled up out of worker. This shouldn't happen. #{err.message}")
        err.backtrace.each do |btr|
          @config.logger.error("  #{btr}")
        end
        headers.reject
      ensure
        worker.bail_out(err)
      end
    end
  end
  wait :spin_down
ensure
  client.close
end