Class: LoopDance::Controller

Inherits:
DaemonController
  • Object
show all
Defined in:
lib/loop_dance/controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_fileObject



27
28
29
# File 'lib/loop_dance/controller.rb', line 27

def log_file
  dancer.pid_file.gsub '.pid', '.log'
end

.new(dancer) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/loop_dance/controller.rb', line 12

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

.start_commandObject



31
32
33
34
35
36
37
38
# File 'lib/loop_dance/controller.rb', line 31

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

Instance Method Details

#safely_startObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/loop_dance/controller.rb', line 41

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_stopObject



53
54
55
56
57
58
# File 'lib/loop_dance/controller.rb', line 53

def safely_stop
  dancer.log  "Stopping.."
  stop if running?
rescue => exception # DaemonController::StartTimeout
  log_exception exception
end