Sha256: 8b03743da279f128a42de3bfdc6caa6eea67d63036491f0623458403713aab44

Contents?: true

Size: 1.55 KB

Versions: 7

Compression:

Stored size: 1.55 KB

Contents

require 'celluloid'

class Eye::ChildProcess

  include Celluloid

  # needs: kill_process
  include Eye::Process::Commands

  # easy config + defaults: prepare_config, c, []
  include Eye::Process::Config

  # conditional watchers: start_checkers
  include Eye::Process::Watchers

  # system methods: send_signal
  include Eye::Process::System

  # self_status_data
  include Eye::Process::Data

  # manage notify methods
  include Eye::Process::Notify

  # scheduler
  include Eye::Process::Scheduler

  attr_reader :pid, :name, :full_name, :config, :watchers

  def initialize(pid, config = {}, logger_prefix = nil, parent = nil)
    raise 'Empty pid' unless pid

    @pid = pid
    @config = prepare_config(config)
    @name = "child-#{pid}"
    @full_name = [logger_prefix, @name].join(':')

    @watchers = {}

    @scheduler_history = parent.scheduler_history
    @parent_pid = parent.pid

    debug { "start monitoring CHILD config: #{@config.inspect}" }

    start_checkers
  end

  def logger_tag
    full_name
  end

  def state
    :up
  end

  def up?
    state == :up
  end

  def start; end

  def stop
    kill_process
  end

  def restart
    if self[:restart_command]
      execute_restart_command
    else
      stop
    end
  end

  def monitor; end

  def unmonitor; end

  def delete; end

  def destroy
    remove_watchers
    terminate
  end

  def signal(sig)
    send_signal(sig) if pid
  end

  def status_data(opts = {})
    self_status_data(opts)
  end

  # override
  def prepare_command(command)
    super.gsub('{PARENT_PID}', @parent_pid.to_s)
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eye-0.10.1.pre lib/eye/child_process.rb
eye-0.10.0 lib/eye/child_process.rb
eye-0.10.0.alpha2 lib/eye/child_process.rb
eye-0.10.0.alpha lib/eye/child_process.rb
eye-0.9.4.nosigar lib/eye/child_process.rb
eye-0.9.4 lib/eye/child_process.rb
eye-0.9.3 lib/eye/child_process.rb