Module: Bj::Runner::ClassMethods

Defined in:
lib/bj/runner.rb

Instance Method Summary collapse

Instance Method Details

#backgroundObject



86
87
88
# File 'lib/bj/runner.rb', line 86

def background
  @background ||= Hash.new
end

#background=(value) ⇒ Object



90
91
92
# File 'lib/bj/runner.rb', line 90

def background= value
  @background ||= value 
end

#commandObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/bj/runner.rb', line 94

def command
  %W[
    #{ Bj.ruby } #{ Bj.script } run 
    --forever 
    --redirect=#{ log }
    --ppid=#{ Process.pid }
    --rails_env=#{ Bj.rails_env }
    --rails_root=#{ Bj.rails_root }
  ].join(" ")
end

#keyObject



72
73
74
# File 'lib/bj/runner.rb', line 72

def key
  "#{ Bj.rails_env }.pid"
end

#logObject



105
106
107
# File 'lib/bj/runner.rb', line 105

def log
  File.join logdir, "bj.#{ Bj.hostname }.#{ Bj.rails_env }.log"
end

#logdirObject



109
110
111
# File 'lib/bj/runner.rb', line 109

def logdir
  File.join File.expand_path(Bj.rails_root), 'log'
end

#no_tickle_keyObject



76
77
78
# File 'lib/bj/runner.rb', line 76

def no_tickle_key 
  "#{ Bj.rails_env }.no_tickle"
end

#pingObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bj/runner.rb', line 60

def ping
  pid = Bj.config[Runner.key]
  return nil unless pid
  pid = Integer pid
  begin
    Process.kill Runner.signal, pid
    pid
  rescue Exception 
    false
  end
end

#run(options = {}, &block) ⇒ Object



113
114
115
# File 'lib/bj/runner.rb', line 113

def run options = {}, &block
  new(options, &block).run
end

#start(options = {}) ⇒ Object



80
81
82
83
84
# File 'lib/bj/runner.rb', line 80

def start options = {}
  options.to_options!
  background.delete Bj.rails_env if options[:force]
  background[Bj.rails_env] ||= Background.for(command)
end

#tickleObject



55
56
57
58
# File 'lib/bj/runner.rb', line 55

def tickle
  return nil if Bj.config[Runner.no_tickle_key]
  ping or start
end