class LoopDance::Controller

Public Class Methods

log_file() click to toggle source
# File lib/loop_dance/controller.rb, line 26
def log_file
  dancer.pid_file.gsub '.pid', '.log'
end
new( dancer ) click to toggle source
Calls superclass method
# File lib/loop_dance/controller.rb, line 10
def new( dancer )
  self.dancer = dancer
  h = {
    :identifier => dancer.name,
    :daemonize_for_me => true,
    :start_command => start_command,
    :ping_command => lambda { true },
    :pid_file => dancer.pid_file,
    :log_file => log_file,
    :start_timeout => dancer.start_timeout,
    :stop_timeout => dancer.stop_timeout,
    :log_file_activity_timeout => dancer.log_file_activity_timeout
  }
  super h
end
start_command() click to toggle source
# File lib/loop_dance/controller.rb, line 30
def start_command
  if defined? Rails
    "rails runner -e #{Rails.env} '#{dancer}.dance' 2>&1 >>#{log_file}"
  else
    "rails runner '#{dancer}.dance' 2>&1 >>#{log_file}"
  end
  
end

Public Instance Methods

safely_restart() click to toggle source
# File lib/loop_dance/controller.rb, line 52
def safely_restart
  dancer.log  "Retarting.. (#{@start_command})"
  if running?
    dancer.log "Dancer is already running, stop"
    stop
    dancer.log "Start"
    start
  else
    start
    dancer.log "Started"
  end
rescue => exception # DaemonController::StartTimeout
  log_exception exception
end
safely_start() click to toggle source
# File lib/loop_dance/controller.rb, line 40
def safely_start
  dancer.log  "Starting.. (#{@start_command})"
  if running?
    dancer.log "Dancer is already running"
  else
    start
    dancer.log "Started"
  end
rescue => exception # DaemonController::StartTimeout
  log_exception exception
end
safely_stop() click to toggle source
# File lib/loop_dance/controller.rb, line 67
def safely_stop
  dancer.log  "Stopping.."
  stop if running?
rescue => exception # DaemonController::StartTimeout
  log_exception exception
end

Private Instance Methods

log_exception( exception ) click to toggle source

stop start running

# File lib/loop_dance/controller.rb, line 80
def log_exception( exception )
  dancer.log "Exception #{dancer}: #{exception.inspect}"
  dancer.log  exception.backtrace if exception.inspect=~/DaemonController/ && defined?( Rails ) && !Rails.env.production? 
end