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())
# Each check may then individually be configured to run every N * tick
config.install_attr('base_tick', 60)
# How often we retry checks that are in error (-1 disables feature)
config.install_attr('error_every', -1)
# Default "every" check parameter, can be overridden on a per-check basis
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)
config.install_attr('verb_level', 'INFO')
......
......@@ -28,11 +28,13 @@ class Checks(list):
class Check(object):
def __init__(self, **options):
from . import config
self._options = options
self.retry = options.get('retry', 0)
self.retry_count = 0
self.every = options.get('every', 1)
self.every_count = 0
self.every = options.get('every', config.default_every)
self.error_every = options.get('error_every', config.default_error_every)
self.run_count = 0
self.errmsg = ''
self.ok = True
self.target_name = options.get('target_name', 'Unknown')
......@@ -40,7 +42,7 @@ class Check(object):
def __repr__(self):
return '{:<15s} N={}/{}, R={}/{}, {}'.format(self.__class__.__name__,
self.every_count,
self.run_count,
self.every,
self.retry_count,
self.retry,
......@@ -56,12 +58,11 @@ class Check(object):
pass
def run(self, immediate=False):
from . import config
self.every_count = (self.every_count + 1) % (
self.every if self.ok or
config.error_every < 0
else config.error_every)
if self.every_count == 0 or immediate:
self.run_count = (self.run_count + 1) % (
self.every if self.ok or
self.error_every < 0
else self.error_every)
if self.run_count == 0 or immediate:
logging.debug('Running ' + str(self))
self.setup()
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