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
# File 'lib/daemon_kit/ruote_participants.rb', line 35

def initialize
  @transports = []
  @participants = {}

  @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

#configure(&block) ⇒ Object

Yields self and configures the remote participants



43
44
45
46
47
48
# File 'lib/daemon_kit/ruote_participants.rb', line 43

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.



68
69
70
71
72
73
74
75
76
# File 'lib/daemon_kit/ruote_participants.rb', line 68

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



79
80
81
# File 'lib/daemon_kit/ruote_participants.rb', line 79

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

#use(transport) ⇒ Object

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



52
53
54
# File 'lib/daemon_kit/ruote_participants.rb', line 52

def use( transport )
  @transports << transport
end