From 8f7448257efa809726498e7a617a132a7020d95e Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Sat, 20 Jan 2018 00:47:08 +0100 Subject: [PATCH] Implement exponential backoff (and recovery) for main timer. --- AutoTx/AutoTx.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 63cce27..a1423d1 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -421,13 +421,19 @@ namespace AutoTx try { RunMainTasks(); GC.Collect(); + // if everything went fine, reset the timer interval to its default value, so the + // service can even recover from temporary problems itself (see below): + _mainTimer.Interval = _config.ServiceTimer; } catch (Exception ex) { - // TODO / FIXME: combine log and admin-email! - var msg = string.Format("Error in OnTimedEvent(): {0}", ex.Message); - Log.Error(msg); - SendAdminEmail(msg); - Log.Debug("Extended Error Info (StackTrace): {0}", ex.StackTrace); + // in case an Exception is reaching this level there is a good chance it is a + // permanent / recurring problem, therefore we increase the timer interval each + // time by a factor of ten (to avoid triggering the same issue every second and + // flooding the admins with emails): + _mainTimer.Interval *= 10; + Log.Error("Unhandled exception in OnTimedEvent(): {0}\n\n" + + "Trying exponential backoff, increasing timer interval to {1} ms.\n\n" + + "StackTrace: {2}", ex.Message, _mainTimer.Interval, ex.StackTrace); } finally { // make sure to enable the timer again: -- GitLab