Class: KeepRunning
- Inherits:
-
Object
- Object
- KeepRunning
- Defined in:
- lib/keep_running.rb,
lib/keep_running/version.rb
Constant Summary collapse
- VERSION =
'0.0.4'
Class Method Summary collapse
- .load_runner(runner) ⇒ Object
- .process_argv ⇒ Object
- .run(&block) ⇒ Object
- .runner_location ⇒ Object
Instance Method Summary collapse
- #email(e) ⇒ Object
- #pidfile(p) ⇒ Object
- #process(p) ⇒ Object
- #restart_delay(d) ⇒ Object
- #restart_threshold(t) ⇒ Object
- #run ⇒ Object
Class Method Details
.load_runner(runner) ⇒ Object
6 7 8 |
# File 'lib/keep_running.rb', line 6 def load_runner(runner) load @runner_location = runner end |
.process_argv ⇒ Object
14 15 16 |
# File 'lib/keep_running.rb', line 14 def process_argv ARGV.shift if File.basename($0) == 'keep_running' end |
.run(&block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/keep_running.rb', line 18 def run(&block) runner = new process_argv runner.instance_eval &block runner.run end |
.runner_location ⇒ Object
10 11 12 |
# File 'lib/keep_running.rb', line 10 def runner_location @runner_location ||= File.($0) end |
Instance Method Details
#email(e) ⇒ Object
27 |
# File 'lib/keep_running.rb', line 27 def email(e) ; @email_opts = e ; end |
#pidfile(p) ⇒ Object
26 |
# File 'lib/keep_running.rb', line 26 def pidfile(p) ; @pidfile = p ; end |
#process(p) ⇒ Object
30 31 32 |
# File 'lib/keep_running.rb', line 30 def process(p) @process = File.(File.join(File.dirname(self.class.runner_location), p)) end |
#restart_delay(d) ⇒ Object
29 |
# File 'lib/keep_running.rb', line 29 def restart_delay(d) ; @restart_delay = d ; end |
#restart_threshold(t) ⇒ Object
28 |
# File 'lib/keep_running.rb', line 28 def restart_threshold(t) ; @restart_threshold = t ; end |
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/keep_running.rb', line 34 def run write_pidfile output = nil loop do output = spawn { start_process } # load the given script send_mail subject(@process), output # send the email throttle_restart # don't restart too fast end end |