Sha256: e1a334d373724f9546670ef8a521ab7dc68f684a2388cb4ba7570e5ae2e67e66

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

module Bluepill
  class Group
    attr_accessor :name, :processes, :logger
    attr_accessor :process_logger
    
    def initialize(name, options = {})
      self.name = name
      self.processes = []
      self.logger = options[:logger]
    end
    
    def add_process(process)
      process.logger = self.logger.prefix_with(process.name)
      self.processes << process
    end
    
    def tick
      self.processes.each do |process|
        process.tick
      end
    end

    # proxied events
    [:start, :unmonitor, :stop, :restart, :boot].each do |event|
      class_eval <<-END
        def #{event}(process_name = nil)
          threads = []
          affected = []
          self.processes.each do |process|
            next if process_name && process_name != process.name
            affected << [self.name, process.name].join(":")
            threads << Thread.new { process.handle_user_command("#{event}") }
          end
          threads.each { |t| t.join }
          affected
        end      
      END
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
bluepill-0.0.28 lib/bluepill/group.rb
bluepill-0.0.27 lib/bluepill/group.rb
gvarela-bluepill-0.0.28 lib/bluepill/group.rb
gvarela-bluepill-0.0.27 lib/bluepill/group.rb
bluepill-0.0.26 lib/bluepill/group.rb
bluepill-0.0.25 lib/bluepill/group.rb