Skip to content
Snippets Groups Projects
Commit 8f744825 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Implement exponential backoff (and recovery) for main timer.

parent 2ab40ae7
No related branches found
No related tags found
No related merge requests found
...@@ -421,13 +421,19 @@ namespace AutoTx ...@@ -421,13 +421,19 @@ namespace AutoTx
try { try {
RunMainTasks(); RunMainTasks();
GC.Collect(); 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) { catch (Exception ex) {
// TODO / FIXME: combine log and admin-email! // in case an Exception is reaching this level there is a good chance it is a
var msg = string.Format("Error in OnTimedEvent(): {0}", ex.Message); // permanent / recurring problem, therefore we increase the timer interval each
Log.Error(msg); // time by a factor of ten (to avoid triggering the same issue every second and
SendAdminEmail(msg); // flooding the admins with emails):
Log.Debug("Extended Error Info (StackTrace): {0}", ex.StackTrace); _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 { finally {
// make sure to enable the timer again: // make sure to enable the timer again:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment