Sha256: eadda94847f55ace99762809bc5fcc72c6edc2e2904f06f4605a744d5e81bed6
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
require 'daemon_controller' module LoopDance class Controller < DaemonController cattr_accessor :dancer, :start_timeout self.start_timeout = 45 class << self 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 => start_timeout, :log_file_activity_timeout => dancer.maximal_timeout + 3 # 3 seconds to stock } super h end def log_file dancer.pid_file.gsub '.pid', '.log' end 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 end 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 def safely_stop dancer.log "Stopping.." stop if running? rescue => exception # DaemonController::StartTimeout log_exception exception end #stop #start #running private def log_exception( exception ) dancer.log "Exception #{dancer}: #{exception.inspect}" dancer.log exception.backtrace if exception.inspect=~/DaemonController/ && defined?( Rails ) && !Rails.env.production? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loop_dance-0.2.5 | lib/loop_dance/controller.rb |