Class: Freyr::ServiceGroup
- Inherits:
-
Array
- Object
- Array
- Freyr::ServiceGroup
- Extended by:
- Forwardable
- Includes:
- TSort
- Defined in:
- lib/freyr/service_group.rb
Instance Method Summary collapse
- #call_graph ⇒ Object
- #find_by_name(n) ⇒ Object
-
#initialize(*services) ⇒ ServiceGroup
constructor
A new instance of ServiceGroup.
- #inspect ⇒ Object
- #restart ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
- #tsort_each_child(node, &blk) ⇒ Object
- #tsort_each_node(&blk) ⇒ Object
- #update_services ⇒ Object
Constructor Details
#initialize(*services) ⇒ ServiceGroup
Returns a new instance of ServiceGroup.
8 9 10 11 |
# File 'lib/freyr/service_group.rb', line 8 def initialize *services @all_services = [] super(services) end |
Instance Method Details
#call_graph ⇒ Object
28 29 30 31 32 |
# File 'lib/freyr/service_group.rb', line 28 def call_graph @call_graph ||= inject(Hash.new {|h,k| h[k]=[]}) do |graph, svc| graph.merge(svc.call_graph) end end |
#find_by_name(n) ⇒ Object
13 14 15 |
# File 'lib/freyr/service_group.rb', line 13 def find_by_name(n) find {|s| s.name == n} end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/freyr/service_group.rb', line 24 def inspect %Q{#<#{self.class.inspect} #{@_dc_obj.collect{|s| s.name}.join(', ')}>} end |
#restart ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/freyr/service_group.rb', line 55 def restart names = collect {|s| s.name} each do |s| Freyr.logger.debug('restart service') {s.name} s.restart! names.delete(s.name) end names end |
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/freyr/service_group.rb', line 34 def run return [] if empty? @call_graph = nil # Make sure it's getting the latest graph services = call_order services.collect do |service| service.name if service.start! end end |
#stop ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/freyr/service_group.rb', line 45 def stop changed_names = collect {|s| s.name if s.alive?}.compact each do |svc| Freyr.logger.debug('stopping service') {svc.name} svc.stop! end changed_names end |
#tsort_each_child(node, &blk) ⇒ Object
71 72 73 |
# File 'lib/freyr/service_group.rb', line 71 def tsort_each_child(node, &blk) call_graph[node].each(&blk) end |
#tsort_each_node(&blk) ⇒ Object
67 68 69 |
# File 'lib/freyr/service_group.rb', line 67 def tsort_each_node &blk call_graph.keys.each(&blk) end |
#update_services ⇒ Object
17 18 19 20 21 22 |
# File 'lib/freyr/service_group.rb', line 17 def update_services dependencies = inject([]) do |deps,svc| deps | svc.dependencies(true) end @all_services = dependencies|@_dc_obj end |