Class: DaemonKit::RuoteParticipants
- 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
-
#participants ⇒ Object
readonly
Returns the value of attribute participants.
Class Method Summary collapse
-
.configure(&block) ⇒ Object
Configure this daemon as a remote participant to ruote.
- .instance ⇒ Object
-
.run(&block) ⇒ Object
Activate and run the remote participant code, calling the optional block for additional daemon logic.
Instance Method Summary collapse
-
#configure(&block) ⇒ Object
Yields
self
and configures the remote participants. -
#initialize ⇒ RuoteParticipants
constructor
A new instance of RuoteParticipants.
-
#register(*args) ⇒ Object
Register classes as pseudo-participants.
-
#run(&block) ⇒ Object
Run the participants.
-
#subscribe_to(queue) ⇒ Object
Subscribe to additional queues not specified in ruote.yml.
-
#use(transport) ⇒ Object
Enable the use of a specific transport for workitems.
Constructor Details
#initialize ⇒ RuoteParticipants
Returns a new instance of RuoteParticipants.
35 36 37 38 39 40 41 |
# File 'lib/daemon_kit/ruote_participants.rb', line 35 def initialize @transports = [] @participants = {} @runtime_queues = [] @configuration = Config.load('ruote') end |
Instance Attribute Details
#participants ⇒ Object (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 |
.instance ⇒ Object
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
#configure(&block) ⇒ Object
Yields self
and configures the remote participants
44 45 46 47 48 49 |
# File 'lib/daemon_kit/ruote_participants.rb', line 44 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.
69 70 71 72 73 74 75 76 77 |
# File 'lib/daemon_kit/ruote_participants.rb', line 69 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
80 81 82 |
# File 'lib/daemon_kit/ruote_participants.rb', line 80 def run(&block) run_amqp! if @transports.include?( :amqp ) end |
#subscribe_to(queue) ⇒ Object
Subscribe to additional queues not specified in ruote.yml
85 86 87 |
# File 'lib/daemon_kit/ruote_participants.rb', line 85 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.
53 54 55 |
# File 'lib/daemon_kit/ruote_participants.rb', line 53 def use( transport ) @transports << transport end |