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

#current_status, #initialize

Constructor Details

This class inherits a constructor from Woodhouse::Runner

Instance Method Details

- (Object) bail_out(err)

Raises:



65
66
67
68
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 65

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

- (Object) spin_down



61
62
63
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 61

def spin_down
  signal :spin_down
end

- (Object) subscribe



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
58
59
# File 'lib/woodhouse/runners/hot_bunnies_runner.rb', line 21

def subscribe
  status :spinning_up
  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
  status :subscribed
  queue.subscribe(:ack => true).each(:blocking => false) do |headers, payload|
    status :receiving
    begin
      job = make_job(headers, payload)
      if can_service_job?(job)
        if service_job(job)
          headers.ack
        else
          headers.reject
        end
      else
        status :rejected
        headers.reject
      end
      status :subscribed
    rescue => err
      status :error
      begin
        headers.reject
      ensure
        worker.bail_out(err)
      end
    end
  end
  wait :spin_down
  status :closing
ensure
  client.close
end