Class: DaemonKit::RuoteParticipants

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_kit/ruote_participants.rb

Overview

Class that cleanly abstracts away the different remote participants in ruote and allows daemon writers to just worry about processing workitems without worrying over the transport mechanism or anything elseā€¦

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RuoteParticipants) initialize



35
36
37
38
39
40
41
42
# File 'lib/daemon_kit/ruote_participants.rb', line 35

def initialize
  @transports = []
  @participants = {}
  @runtime_queues = []
  @amqp_reply_queue = 'ruote_workitems'

  @configuration = Config.load('ruote')
end

Instance Attribute Details

- (Object) participants (readonly)

Returns the value of attribute participants



33
34
35
# File 'lib/daemon_kit/ruote_participants.rb', line 33

def participants
  @participants
end

Class Method Details

+ (Object) configure(&block)

Configure this daemon as a remote participant to ruote.



10
11
12
# File 'lib/daemon_kit/ruote_participants.rb', line 10

def configure(&block)
  instance.configure(&block)
end

+ (Object) instance



22
23
24
# File 'lib/daemon_kit/ruote_participants.rb', line 22

def instance
  @instance ||= new
end

+ (Object) run(&block)

Activate and run the remote participant code, calling the optional block for additional daemon logic.



16
17
18
# File 'lib/daemon_kit/ruote_participants.rb', line 16

def run(&block)
  instance.run(&block)
end

Instance Method Details

- (Object) amqp_reply_queue(name)

Set the name of the AMQP queue that a remote RuoteAMQP::Receiver is listening to (defaults to 'ruote_workitems')



60
61
62
# File 'lib/daemon_kit/ruote_participants.rb', line 60

def amqp_reply_queue( name )
  @amqp_reply_queue = name
end

- (Object) configure(&block)

Yields self and configures the remote participants



45
46
47
48
49
50
# File 'lib/daemon_kit/ruote_participants.rb', line 45

def configure(&block)
  block.call( self )

  @transports.freeze
  @participants.freeze
end

- (Object) register(*args)

Register classes as pseudo-participants. Two styles of registration are supported:

register( Foo )
register( 'short', ShortParticipant )

The first format uses the class name (downcased and underscored) as the key for identifying the pseudo-participant, the second uses the the provided key.

Pseudo-participant classes are instantiated when registered, and the instances are re-used.



76
77
78
79
80
81
82
83
84
# File 'lib/daemon_kit/ruote_participants.rb', line 76

def register( *args )
  key, klass = if args.size == 1
    [ underscore( args.first.to_s ), args.first ]
  else
    [ args[0].to_s, args[1] ]
  end

  @participants[ key ] = klass.new
end

- (Object) run(&block)

Run the participants



87
88
89
# File 'lib/daemon_kit/ruote_participants.rb', line 87

def run(&block)
  run_amqp! if @transports.include?( :amqp )
end

- (Object) subscribe_to(queue)

Subscribe to additional queues not specified in ruote.yml



92
93
94
# File 'lib/daemon_kit/ruote_participants.rb', line 92

def subscribe_to( queue )
  @runtime_queues << queue
end

- (Object) use(transport)

Enable the use of a specific transport for workitems. Can be :amqp to use the AMQPParticipant/AMQPListener pair in ruote.



54
55
56
# File 'lib/daemon_kit/ruote_participants.rb', line 54

def use( transport )
  @transports << transport
end