Sha256: 992a87f4556adfed554f91499d05e55ff6aa96ad33f815470cbe5490c52ff9d3

Contents?: true

Size: 1.92 KB

Versions: 26

Compression:

Stored size: 1.92 KB

Contents

# -*- encoding: utf-8 -*-
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

    def determine_initial_state
      self.processes.each do |process|
        process.determine_initial_state
      end
    end

    # proxied events
    [:start, :unmonitor, :stop, :restart].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

    def status(process_name = nil)
      lines = []
      if process_name.nil?
        prefix = self.name ? "  " : ""
        lines << "#{self.name}:" if self.name

        self.processes.each do |process|
          lines << "%s%s(pid:%s): %s" % [prefix, process.name, process.actual_pid, process.state]
          if process.monitor_children?
            process.children.each do |child|
              lines << "  %s%s: %s" % [prefix, child.name, child.state]
            end
          end
        end
      else
        self.processes.each do |process|
          next if process_name != process.name
          lines << "%s%s(pid:%s): %s" % [prefix, process.name, process.actual_pid, process.state]
          lines << process.statistics.to_s
        end
      end
      lines << ""
    end

  end
end

Version data entries

26 entries across 26 versions & 6 rubygems

Version Path
bluepill-rwgps-0.0.63 lib/bluepill/group.rb
bluepill-rwgps-0.0.62 lib/bluepill/group.rb
bluepill-rwgps-0.0.61 lib/bluepill/group.rb
cloud66-bluepill-0.0.64 lib/bluepill/group.rb
bluepill-rwgps-0.0.60 lib/bluepill/group.rb
cloud66-bluepill-0.0.63 lib/bluepill/group.rb
cloud66-bluepill-0.0.62 lib/bluepill/group.rb
bluepill-0.0.62 lib/bluepill/group.rb
bluepill-0.0.61 lib/bluepill/group.rb
kostya-bluepill-0.0.60.3 lib/bluepill/group.rb
skalar-bluepill-0.0.60.1 lib/bluepill/group.rb
bluepill-0.0.60 lib/bluepill/group.rb
bluepill-0.0.59 lib/bluepill/group.rb
bluepill-0.0.58 lib/bluepill/group.rb
bluepill-0.0.57 lib/bluepill/group.rb
bluepill-0.0.56 lib/bluepill/group.rb
bluepill-0.0.55 lib/bluepill/group.rb
bluepill-0.0.54 lib/bluepill/group.rb
bluepill-0.0.53 lib/bluepill/group.rb
bluepill-0.0.52 lib/bluepill/group.rb