jnewland / god_examples

examples of some of the crazy awesome things you can do with God

This URL has Read+Write access

god_examples / custom_behvaior.god
100644 41 lines (30 sloc) 0.66 kb
1
2
3
4
5
6
7
8
9
10
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
module God
  module Behaviors
    class Speak < Behavior
 
      def before_start
        `say "Starting now"`
 
        'announced start'
      end
 
      def before_stop
        `say "Stopping now"`
 
        'announced stop'
      end
 
    end
  end
end
 
God.watch do |w|
  w.name = "leaky"
  w.interval = 5.second
  w.start = 'ruby ' + File.dirname(__FILE__) + '/scripts/leaky.rb'
 
  w.behavior(:speak)
 
  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 = 2.megabytes
    end
  end
 
end