Class: Jah::Prayer
- Inherits:
-
Object
- Object
- Jah::Prayer
- Defined in:
- lib/jah/prayer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config) ⇒ Prayer
constructor
A new instance of Prayer.
-
#ping ⇒ Object
ping server to ensure that it is responsive.
- #setup ⇒ Object
Constructor Details
#initialize(config) ⇒ Prayer
Returns a new instance of Prayer.
5 6 7 8 9 |
# File 'lib/jah/prayer.rb', line 5 def initialize(config) @config = config setup ping end |
Class Method Details
.watch(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jah/prayer.rb', line 11 def self.watch( = {}) God.watch do |w| w.name = "jah" w.interval = 1.minute w.start = "jah #{[:config]}" w.start_grace = 10.seconds w.restart_grace = 10.seconds w.start_if do |start| start.condition(:process_running) do |c| c.running = false end end w.restart_if do |restart| restart.condition(:memory_usage) do |c| c.above = 30.megabytes c.times = [3, 5] end restart.condition(:cpu_usage) do |c| c.above = 25.percent c.times = 5 end end w.lifecycle do |on| on.condition(:flapping) do |c| c.to_state = [:start, :restart] c.times = 5 c.within = 5.minute c.transition = :unmonitored c.retry_in = 10.minutes c.retry_times = 5 c.retry_within = 2.hours end end end end |
Instance Method Details
#ping ⇒ Object
ping server to ensure that it is responsive
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jah/prayer.rb', line 60 def ping if god? tries = 3 begin @server.ping rescue Exception => e retry if (tries -= 1) > 1 raise e, "The server is not available (or you do not have permissions to access it)" end end end |
#setup ⇒ Object
52 53 54 55 56 57 |
# File 'lib/jah/prayer.rb', line 52 def setup DRb.start_service @server = DRbObject.new(nil, God::Socket.socket(@config['god_port'])) || nil rescue => e @config[:god] = false end |