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

#initializeRuoteParticipants

Returns a new instance of RuoteParticipants



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

#participantsObject (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

.configure(&block) ⇒ Object

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

.instanceObject



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

def instance
  @instance ||= new
end

.run(&block) ⇒ Object

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

#amqp_reply_queue(name) ⇒ Object

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

#configure(&block) ⇒ Object

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

#register(*args) ⇒ Object

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

#run(&block) ⇒ Object

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

#subscribe_to(queue) ⇒ Object

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

#use(transport) ⇒ Object

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