Commit 00d741fe authored by Jonathan Michalon's avatar Jonathan Michalon

Propose default 'every' and 'error_every' params, overridable

Now the 'every' check parameter can have a default value set globally and the
former global 'error_every' parameter can be overridden on a per-check
basis, so that the two parameters' configuration is now homogenous
and much more flexible.
parent bb1ba3b2
...@@ -12,8 +12,12 @@ config.install_attr('checks', Checks()) ...@@ -12,8 +12,12 @@ config.install_attr('checks', Checks())
# Each check may then individually be configured to run every N * tick # Each check may then individually be configured to run every N * tick
config.install_attr('base_tick', 60) config.install_attr('base_tick', 60)
# How often we retry checks that are in error (-1 disables feature) # Default "every" check parameter, can be overridden on a per-check basis
config.install_attr('error_every', -1) config.install_attr('default_every', 1)
# Default "error_every" (how often we retry checks that are in error) parameter
# -1 disables feature (same as regular "every"), can be also be overridden
config.install_attr('default_error_every', -1)
# Verbosity level (one of CRITICAL, ERROR, WARNING, INFO, DEBUG) # Verbosity level (one of CRITICAL, ERROR, WARNING, INFO, DEBUG)
config.install_attr('verb_level', 'INFO') config.install_attr('verb_level', 'INFO')
......
...@@ -28,11 +28,13 @@ class Checks(list): ...@@ -28,11 +28,13 @@ class Checks(list):
class Check(object): class Check(object):
def __init__(self, **options): def __init__(self, **options):
from . import config
self._options = options self._options = options
self.retry = options.get('retry', 0) self.retry = options.get('retry', 0)
self.retry_count = 0 self.retry_count = 0
self.every = options.get('every', 1) self.every = options.get('every', config.default_every)
self.every_count = 0 self.error_every = options.get('error_every', config.default_error_every)
self.run_count = 0
self.errmsg = '' self.errmsg = ''
self.ok = True self.ok = True
self.target_name = options.get('target_name', 'Unknown') self.target_name = options.get('target_name', 'Unknown')
...@@ -40,7 +42,7 @@ class Check(object): ...@@ -40,7 +42,7 @@ class Check(object):
def __repr__(self): def __repr__(self):
return '{:<15s} N={}/{}, R={}/{}, {}'.format(self.__class__.__name__, return '{:<15s} N={}/{}, R={}/{}, {}'.format(self.__class__.__name__,
self.every_count, self.run_count,
self.every, self.every,
self.retry_count, self.retry_count,
self.retry, self.retry,
...@@ -56,12 +58,11 @@ class Check(object): ...@@ -56,12 +58,11 @@ class Check(object):
pass pass
def run(self, immediate=False): def run(self, immediate=False):
from . import config self.run_count = (self.run_count + 1) % (
self.every_count = (self.every_count + 1) % ( self.every if self.ok or
self.every if self.ok or self.error_every < 0
config.error_every < 0 else self.error_every)
else config.error_every) if self.run_count == 0 or immediate:
if self.every_count == 0 or immediate:
logging.debug('Running ' + str(self)) logging.debug('Running ' + str(self))
self.setup() self.setup()
if not self.check(): if not self.check():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment