diff options
author | 2011-01-23 18:16:30 -0500 | |
---|---|---|
committer | 2011-01-23 18:16:30 -0500 | |
commit | 997ba73ed8bc1b1d1e181570f6211ea6d0f68335 (patch) | |
tree | e667f8ad9df5e0e7f41b0bbc2f2d4f074eb0ccc2 /src | |
parent | fa0d31c65e80bc15ca5bfbb6e22f1f68674f3dab (diff) |
Proper error handling for periodic tasks
Diffstat (limited to 'src')
-rw-r--r-- | src/c/request.c | 18 | ||||
-rw-r--r-- | src/c/urweb.c | 9 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/c/request.c b/src/c/request.c index 4372c074..a5f0e2f1 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -96,10 +96,26 @@ static void *periodic_loop(void *data) { 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); }; diff --git a/src/c/urweb.c b/src/c/urweb.c index 67df7a2e..693cc87f 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -3684,15 +3684,12 @@ uw_Basis_postBody uw_getPostBody(uw_context ctx) { failure_kind uw_runCallback(uw_context ctx, void (*callback)(uw_context)) { int r = setjmp(ctx->jmp_buf); - if (ctx->app->db_begin(ctx)) - uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN"); - if (r == 0) { + if (ctx->app->db_begin(ctx)) + uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN"); + callback(ctx); - uw_commit(ctx); } - else - uw_rollback(ctx, 0); return r; } |