diff src/c/request.c @ 1418:22674ac8ebe6

Proper error handling for periodic tasks
author Adam Chlipala <adam@chlipala.net>
date Sun, 23 Jan 2011 18:16:30 -0500
parents d0786ff9bb22
children 493e087f5479
line wrap: on
line diff
--- a/src/c/request.c	Sun Jan 23 17:27:51 2011 -0500
+++ b/src/c/request.c	Sun Jan 23 18:16:30 2011 -0500
@@ -96,10 +96,26 @@
     exit(1);
 
   while (1) {
+    int retries_left = MAX_RETRIES;
+
     failure_kind r;
     do {
+      uw_reset(ctx);
       r = uw_runCallback(ctx, p->pdic.callback);
-    } while (r == UNLIMITED_RETRY);
+      if (r == BOUNDED_RETRY)
+        --retries_left;
+      else if (r == UNLIMITED_RETRY)
+        p->ls->log_debug(p->ls->logger_data, "Error triggers unlimited retry in periodic: %s\n", uw_error_message(ctx));
+      else if (r == BOUNDED_RETRY)
+        p->ls->log_debug(p->ls->logger_data, "Error triggers bounded retry in periodic: %s\n", uw_error_message(ctx));
+      else if (r == FATAL)
+        p->ls->log_error(p->ls->logger_data, "Fatal error: %s\n", uw_error_message(ctx));
+      if (r == FATAL || r == BOUNDED_RETRY || r == UNLIMITED_RETRY)
+        try_rollback(ctx, 0, p->ls->logger_data, p->ls->log_error);
+    } while (r == UNLIMITED_RETRY || (r == BOUNDED_RETRY && retries_left > 0));
+
+    if (r != FATAL && r != BOUNDED_RETRY)
+      uw_commit(ctx);
 
     sleep(p->pdic.period);
   };