diff src/c/urweb.c @ 1349:87156c44824f

Periodic tasks
author Adam Chlipala <adam@chlipala.net>
date Sat, 18 Dec 2010 15:17:09 -0500
parents b106ca8200b1
children 703c2c94afd5
line wrap: on
line diff
--- a/src/c/urweb.c	Sat Dec 18 14:17:45 2010 -0500
+++ b/src/c/urweb.c	Sat Dec 18 15:17:09 2010 -0500
@@ -3492,3 +3492,19 @@
   else
     uw_error(ctx, FATAL, "Asked for POST body when none exists");
 }
+
+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) {
+    callback(ctx);
+    uw_commit(ctx);
+  }
+  else
+    uw_rollback(ctx, 0);
+
+  return r;
+}