comparison 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
comparison
equal deleted inserted replaced
1417:d0786ff9bb22 1418:22674ac8ebe6
94 94
95 if (!ctx) 95 if (!ctx)
96 exit(1); 96 exit(1);
97 97
98 while (1) { 98 while (1) {
99 int retries_left = MAX_RETRIES;
100
99 failure_kind r; 101 failure_kind r;
100 do { 102 do {
103 uw_reset(ctx);
101 r = uw_runCallback(ctx, p->pdic.callback); 104 r = uw_runCallback(ctx, p->pdic.callback);
102 } while (r == UNLIMITED_RETRY); 105 if (r == BOUNDED_RETRY)
106 --retries_left;
107 else if (r == UNLIMITED_RETRY)
108 p->ls->log_debug(p->ls->logger_data, "Error triggers unlimited retry in periodic: %s\n", uw_error_message(ctx));
109 else if (r == BOUNDED_RETRY)
110 p->ls->log_debug(p->ls->logger_data, "Error triggers bounded retry in periodic: %s\n", uw_error_message(ctx));
111 else if (r == FATAL)
112 p->ls->log_error(p->ls->logger_data, "Fatal error: %s\n", uw_error_message(ctx));
113 if (r == FATAL || r == BOUNDED_RETRY || r == UNLIMITED_RETRY)
114 try_rollback(ctx, 0, p->ls->logger_data, p->ls->log_error);
115 } while (r == UNLIMITED_RETRY || (r == BOUNDED_RETRY && retries_left > 0));
116
117 if (r != FATAL && r != BOUNDED_RETRY)
118 uw_commit(ctx);
103 119
104 sleep(p->pdic.period); 120 sleep(p->pdic.period);
105 }; 121 };
106 } 122 }
107 123