public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/Bertg/god.git
fix more broken stuff
mojombo (author)
Thu Jan 24 15:37:20 -0800 2008
commit  b9a0832c664cff4c60fd1787c798b8a774603242
tree    67a5d8afc291475ea9745df75bedba3b8a439862
parent  f2cffe126c48a78a6950896bb9b5c2bf1692aead
...
77
78
79
80
 
81
82
83
...
77
78
79
 
80
81
82
83
0
@@ -77,7 +77,7 @@ module God
0
     end
0
     
0
     def trigger
0
- Hub.trigger(self)
0
+ self.watch.trigger(self)
0
     end
0
     
0
     def register
...
24
25
26
 
27
28
29
...
50
51
52
 
 
 
53
54
55
56
57
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
 
75
76
77
78
 
 
 
 
 
79
80
81
82
83
 
84
85
86
...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
24
25
26
27
28
29
30
...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 
 
66
67
68
69
70
 
 
71
72
 
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
93
94
95
96
...
103
104
105
 
 
 
 
 
 
 
 
106
107
108
109
0
@@ -24,6 +24,7 @@ module God
0
     INTERVAL = 0.25
0
     
0
     # Instantiate a new Driver and start the scheduler loop to handle events
0
+ # +task+ is the Task this Driver belongs to
0
     #
0
     # Returns Driver
0
     def initialize(task)
0
@@ -50,37 +51,46 @@ module God
0
       end
0
     end
0
     
0
+ # Handle the next queued operation that was issued asynchronously
0
+ #
0
+ # Returns nothing
0
     def handle_op
0
       command = @ops.pop
0
       @task.send(command[0], *command[1])
0
     end
0
     
0
+ # Handle the next event (poll condition) that is due
0
+ #
0
+ # Returns nothing
0
     def handle_event
0
- # display_events
0
-
0
       if @events.first.due?
0
         event = @events.shift
0
         @task.handle_poll(event.condition)
0
       end
0
       
0
- # display_events
0
-
0
       # don't sleep if there is a pending event and it is due
0
       unless @events.first && @events.first.due?
0
- # puts 'sleep'
0
         sleep INTERVAL
0
       end
0
     end
0
     
0
+ # Clear all events for this Driver
0
+ #
0
+ # Returns nothing
0
     def clear_events
0
       @events.clear
0
     end
0
     
0
+ # Queue an asynchronous message
0
+ # +name+ is the Symbol name of the operation
0
+ # +args+ is an optional Array of arguments
0
+ #
0
+ # Returns nothing
0
     def message(name, args = [])
0
       @ops.push([name, args])
0
     end
0
     
0
- # Create and register a new TimerEvent
0
+ # Create and schedule a new DriverEvent
0
     # +condition+ is the Condition
0
     # +delay+ is the number of seconds to delay (default: interval defined in condition)
0
     #
0
@@ -93,14 +103,6 @@ module God
0
       # sort events
0
       @events.sort! { |x, y| x.at <=> y.at }
0
     end
0
-
0
- def display_events
0
- puts '+--'
0
- @events.each do |e|
0
- puts "| #{e.condition.friendly_name} - #{e.at.to_f}"
0
- end
0
- puts '+--'
0
- end
0
   end # Driver
0
   
0
 end # God
0
\ No newline at end of file
...
21
22
23
 
 
 
24
25
26
...
56
57
58
59
60
61
62
 
 
 
63
64
65
 
 
66
67
68
69
70
...
21
22
23
24
25
26
27
28
29
...
59
60
61
 
 
 
 
62
63
64
65
 
 
66
67
68
 
69
70
71
0
@@ -21,6 +21,9 @@ module God
0
       self.logs = {}
0
       @mutex = Mutex.new
0
       @capture = nil
0
+ @templogio = StringIO.new
0
+ @templog = ::Logger.new(@templogio)
0
+ @templog.level = Logger::INFO
0
       load_syslog
0
     end
0
     
0
@@ -56,15 +59,13 @@ module God
0
       self.logs[watch.name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT) if watch
0
       
0
       # push onto capture and timeline for the given watch
0
- buf = StringIO.new
0
- templog = ::Logger.new(buf)
0
- templog.level = Logger::INFO
0
- templog.send(level, text % [])
0
+ @templogio.truncate(0)
0
+ @templogio.rewind
0
+ @templog.send(level, text % [])
0
       @mutex.synchronize do
0
- @capture.puts(buf.string) if @capture
0
- self.logs[watch.name] << [Time.now, buf.string] if watch
0
+ @capture.puts(@templogio.string) if @capture
0
+ self.logs[watch.name] << [Time.now, @templogio.string] if watch
0
       end
0
- templog.close
0
       
0
       # send to regular logger
0
       self.send(level, text % [])
...
51
52
53
54
 
55
56
57
...
51
52
53
 
54
55
56
57
0
@@ -51,7 +51,7 @@ module God
0
     
0
     def disable
0
       self.conditions.each do |c|
0
- self.watch.detach(c)
0
+ c.reset
0
       end
0
     end
0
   end
...
110
111
112
 
 
 
 
 
113
114
115
...
132
133
134
 
 
 
135
136
 
 
 
137
138
139
 
140
141
142
143
144
 
 
 
 
145
146
147
...
162
163
164
165
 
166
167
 
168
169
170
171
172
 
 
 
173
174
 
175
176
177
...
110
111
112
113
114
115
116
117
118
119
120
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
...
178
179
180
 
181
182
183
184
185
186
187
188
189
190
191
192
193
 
194
195
196
197
0
@@ -110,6 +110,11 @@ module God
0
       # let the config file define some conditions on the metric
0
       yield(m)
0
       
0
+ # populate the condition -> metric directory
0
+ m.conditions.each do |c|
0
+ self.directory[c] = m
0
+ end
0
+
0
       # record the metric
0
       self.metrics[nil] << m
0
     end
0
@@ -132,16 +137,27 @@ module God
0
     
0
     def move(to_state)
0
       if Thread.current != self.driver.thread
0
+ # called from outside Driver
0
+
0
+ # send an async message to Driver
0
         self.driver.message(:move, [to_state])
0
       else
0
+ # called from within Driver
0
+
0
+ # record original info
0
         orig_to_state = to_state
0
         from_state = self.state
0
         
0
+ # log
0
         msg = "#{self.name} move '#{from_state}' to '#{to_state}'"
0
         applog(self, :info, msg)
0
         
0
         # cleanup from current state
0
         self.driver.clear_events
0
+ self.metrics[from_state].each { |m| m.disable }
0
+ if to_state == :unmonitored
0
+ self.metrics[nil].each { |m| m.disable }
0
+ end
0
         
0
         # perform action
0
         self.action(to_state)
0
@@ -162,16 +178,20 @@ module God
0
         # set state
0
         self.state = to_state
0
         
0
- # trigger
0
+ # broadcast to interested TriggerConditions
0
         Trigger.broadcast(self, :state_change, [from_state, orig_to_state])
0
         
0
+ # log
0
         msg = "#{self.name} moved '#{from_state}' to '#{to_state}'"
0
         applog(self, :info, msg)
0
       end
0
     end
0
     
0
+ # Notify the Driver that an EventCondition has triggered
0
+ #
0
+ # Returns nothing
0
     def trigger(condition)
0
- self.driver.ops << [:handle_event, [condition]]
0
+ self.driver.message(:handle_event, [condition])
0
     end
0
     
0
     ###########################################################################
...
27
28
29
30
31
32
33
34
35
 
 
36
37
38
...
27
28
29
 
 
 
 
 
 
30
31
32
33
34
0
@@ -27,12 +27,8 @@ module God
0
     #
0
     # Returns Timeline
0
     def push(val)
0
- if (size + 1) > @max_size
0
- reverse!
0
- pop
0
- reverse!
0
- end
0
- super(val)
0
+ self.concat([val])
0
+ shift if size > @max_size
0
     end
0
     
0
     # Push a value onto the timeline

Comments

    No one has commented yet.