summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartinko2014-01-30 13:08:34 +0000
committermartinko2014-01-30 13:08:34 +0000
commit115f9742fcca5e784d3afd9bed763ec1d24eaa39 (patch)
tree961554c00aa7b35467299b51f26d776938edb1ba
parent3bed59760b15aa09e85e32360ff4ae57dca6717f (diff)
skytools.scripting: allow to specify exception(s) to suppress for a grace period
It is possible to provide a list of exception names, or reserved keyword “ALL”.
-rw-r--r--python/skytools/scripting.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 04eeb908..68ddc4d3 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -477,7 +477,7 @@ class BaseScript(object):
self.pidfile = self.cf.getfile("pidfile", '')
self.loop_delay = self.cf.getfloat("loop_delay", self.loop_delay)
self.exception_sleep = self.cf.getfloat("exception_sleep", 20)
- self.exception_quiet = self.cf.getbool("exception_quiet", False)
+ self.exception_quiet = self.cf.getlist("exception_quiet", [])
self.exception_grace = self.cf.getfloat("exception_grace", 5*60)
self.exception_reset = self.cf.getfloat("exception_reset", 15*60)
@@ -626,6 +626,10 @@ class BaseScript(object):
if ex.errno != errno.EINTR:
raise
+ def _is_quiet_exception(self, ex):
+ return ((self.exception_quiet == ["ALL"] or ex.__class__.__name__ in self.exception_quiet)
+ and self.last_func_fail and time.time() < self.last_func_fail + self.exception_grace)
+
def exception_hook(self, det, emsg):
"""Called on after exception processing.
@@ -635,11 +639,10 @@ class BaseScript(object):
@param emsg: exception msg
"""
lm = "Job %s crashed: %s" % (self.job_name, emsg)
- if not self.exception_quiet or (self.last_func_fail
- and time.time() > self.last_func_fail + self.exception_grace):
- self.log.exception(lm)
- else:
+ if self._is_quiet_exception(det):
self.log.warning(lm)
+ else:
+ self.log.exception(lm)
def work(self):
"""Here should user's processing happen.
@@ -823,11 +826,10 @@ class DBScript(BaseScript):
sql = sql[:60] + " ..."
lm = "Job %s got error on connection '%s': %s. Query: %s" % (
self.job_name, cname, emsg, sql)
- if not self.exception_quiet or (self.last_func_fail
- and time.time() > self.last_func_fail + self.exception_grace):
- self.log.exception(lm)
- else:
+ if self._is_quiet_exception(d):
self.log.warning(lm)
+ else:
+ self.log.exception(lm)
else:
BaseScript.exception_hook(self, d, emsg)