Class: WatchmonkeyCli::Checker
- Inherits:
-
Object
- Object
- WatchmonkeyCli::Checker
show all
- Defined in:
- lib/watchmonkey_cli/checker.rb
Defined Under Namespace
Modules: AppHelper
Classes: Result
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app) ⇒ Checker
Returns a new instance of Checker.
111
112
113
114
|
# File 'lib/watchmonkey_cli/checker.rb', line 111
def initialize app
@app = app
send(:init) if respond_to?(:init)
end
|
Instance Attribute Details
#app ⇒ Object
109
110
111
|
# File 'lib/watchmonkey_cli/checker.rb', line 109
def app
@app
end
|
Class Method Details
.checker_name ⇒ Object
12
13
14
|
# File 'lib/watchmonkey_cli/checker.rb', line 12
def self.checker_name
@checker_name || self.name
end
|
.checker_name=(name) ⇒ Object
16
17
18
|
# File 'lib/watchmonkey_cli/checker.rb', line 16
def self.checker_name= name
@checker_name = name
end
|
.descendants ⇒ Object
Descendant tracking for inherited classes.
4
5
6
|
# File 'lib/watchmonkey_cli/checker.rb', line 4
def self.descendants
@descendants ||= []
end
|
.inherited(descendant) ⇒ Object
8
9
10
|
# File 'lib/watchmonkey_cli/checker.rb', line 8
def self.inherited(descendant)
descendants << descendant
end
|
Instance Method Details
#_tolog(msg, meth = :log) ⇒ Object
138
139
140
141
|
# File 'lib/watchmonkey_cli/checker.rb', line 138
def _tolog msg, meth = :log
return unless app.opts[:logfile]
app.logger.public_send(meth, msg)
end
|
#check!(*a) ⇒ Object
227
228
229
230
|
# File 'lib/watchmonkey_cli/checker.rb', line 227
def check! *a
raise NotImplementedError, "a checker (#{self.class.name}) must implement `#check!' method!"
end
|
#debug(msg, robj = nil) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/watchmonkey_cli/checker.rb', line 123
def debug msg, robj = nil
app.fire(:on_debug, msg, robj)
app.fire(:on_message, msg, robj)
return if app.opts[:quiet] || app.opts[:silent]
_tolog(msg, :debug)
app.puts app.c(msg, :black)
end
|
#enqueue(*args) ⇒ Object
220
221
222
223
224
225
|
# File 'lib/watchmonkey_cli/checker.rb', line 220
def enqueue *args
raise NotImplementedError, "a checker (#{self.class.name}) must implement `#enqueue' method!"
end
|
#error(msg, robj = nil) ⇒ Object
131
132
133
134
135
136
|
# File 'lib/watchmonkey_cli/checker.rb', line 131
def error msg, robj = nil
app.fire(:on_error, msg, robj)
app.fire(:on_message, msg, robj)
_tolog(msg, :error)
app.sync { app.error(msg) }
end
|
#info(msg, robj = nil) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/watchmonkey_cli/checker.rb', line 116
def info msg, robj = nil
app.fire(:on_info, msg, robj)
return if app.opts[:quiet]
_tolog(msg, :info)
app.puts app.c(msg, :blue)
end
|
#init ⇒ Object
202
203
204
|
# File 'lib/watchmonkey_cli/checker.rb', line 202
def init
end
|
#local ⇒ Object
def to_s
string = "#<#{self.class.name}:#{self.object_id} "
fields = self.class.inspector_fields.map{|field| "#{field}: #{self.send(field)}"}
string << fields.join(", ") << ">"
end
155
156
157
|
# File 'lib/watchmonkey_cli/checker.rb', line 155
def local
@app.fetch_connection(:loopback, :local)
end
|
#rsafe(resultobj, &block) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/watchmonkey_cli/checker.rb', line 177
def rsafe resultobj, &block
tries = 0
begin
tries += 1
block.call
rescue StandardError => e
unless tries > 3
resultobj.sync do
resultobj.error! "retry #{tries} reason is `#{e.class}: #{e.message}'"
e.backtrace.each{|l| resultobj.debug "\t\t#{l}" }
resultobj.dump!
end
sleep 1
retry
end
resultobj.error! "#{descriptor}retries exceeded"
resultobj.dump!
end
end
|
#safe(descriptor = nil, &block) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/watchmonkey_cli/checker.rb', line 159
def safe descriptor = nil, &block
tries = 0
begin
tries += 1
block.call
rescue StandardError => e
unless tries > 3
app.sync do
error "#{descriptor}retry #{tries} reason is `#{e.class}: #{e.message}'"
e.backtrace.each{|l| debug "\t\t#{l}" }
end
sleep 1
retry
end
error "#{descriptor}retries exceeded"
end
end
|
#spawn_sub(which, *args) ⇒ Object
143
144
145
146
147
|
# File 'lib/watchmonkey_cli/checker.rb', line 143
def spawn_sub which, *args
if sec = app.checkers[which.to_s]
sec.enqueue(*args)
end
end
|
#start ⇒ Object
206
207
208
209
|
# File 'lib/watchmonkey_cli/checker.rb', line 206
def start
end
|
#stop ⇒ Object
211
212
213
214
215
216
217
218
|
# File 'lib/watchmonkey_cli/checker.rb', line 211
def stop
end
|