Sha256: e45d934b8e89cf0b80f9031b877617ab3e0b36416238ed518aa08b11cc0e498a

Contents?: true

Size: 1011 Bytes

Versions: 7

Compression:

Stored size: 1011 Bytes

Contents

require 'drb'

class Kryten::RemoteControl
  include DRbUndumped
  attr_reader :job, :workers
  def initialize(job)
    puts "Initialized #{job.name} server on pid #{Process.pid}"
    @job = job
    Signal.trap("TERM") { shutdown }
    Signal.trap("INT") { shutdown }
  end

  def start name=nil
    if name
      worker(name).start_work
    else
      puts "Starting #{job.name}"
      job.start_work
    end
  end

  def stop name=nil
    if name
      worker(name).stop_work
    else
      puts "Stopping #{job.name}"
      val = job.stop_work
      sleep job.timer
      return val
    end
  end

  def shutdown
    puts "Terminating #{job.name}"
    stop
    sleep 2
    exit 0
  end

  def status name=nil
    if name
      worker(name).status
    else
      job.status
    end
  end

  def worker name
    job.workers.detect {|w| w.name == name}
  end

  def workers
    job.workers
  end

  def started
    job.workers.select(&:started)
  end

  def stopped
    job.workers.reject(&:started)
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kryten-0.3.9 lib/kryten/remote.rb
kryten-0.3.8 lib/kryten/remote.rb
kryten-0.3.7 lib/kryten/remote.rb
kryten-0.3.6 lib/kryten/remote.rb
kryten-0.3.5 lib/kryten/remote.rb
kryten-0.3.4 lib/kryten/remote.rb
kryten-0.3.3 lib/kryten/remote.rb