summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-04-12 15:50:42 +0200
committerChristian Grothoff <christian@grothoff.org>2023-04-12 15:50:42 +0200
commitab267651d6dd065b16f2d38fb6651e9db368a9e9 (patch)
tree35e9877e0dfe5928d2033180c62e27a8df705200 /src
parentc176ce9d0402195ee19a1bcae792ee2ccbd33e3b (diff)
downloadmerchant-ab267651d6dd065b16f2d38fb6651e9db368a9e9.tar.gz
merchant-ab267651d6dd065b16f2d38fb6651e9db368a9e9.tar.bz2
merchant-ab267651d6dd065b16f2d38fb6651e9db368a9e9.zip
add logic to persist progress
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-wirewatch.c53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c
index d78d9dbd..77cec3d3 100644
--- a/src/backend/taler-merchant-wirewatch.c
+++ b/src/backend/taler-merchant-wirewatch.c
@@ -106,6 +106,37 @@ static char *instance_id;
static uint64_t start_row;
/**
+ * Set to true if we need to update instead of insert on the merchant_wirewatch table.
+ */
+static bool progress_update;
+
+
+/**
+ * Save progress in DB.
+ */
+static void
+save (void)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ if (progress_update)
+ qs = db_plugin->update_wirewatch_progress (db_plugin->cls,
+ section,
+ start_row);
+ else
+ qs = db_plugin->insert_wirewatch_progress (db_plugin->cls,
+ section,
+ start_row);
+ if (qs <= 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to persist wirewatch progress (%d)\n",
+ qs);
+ }
+}
+
+
+/**
* We're being aborted with CTRL-C (or SIGTERM). Shut down.
*
* @param cls closure
@@ -126,7 +157,7 @@ shutdown_task (void *cls)
TALER_MERCHANT_BANK_credit_history_cancel (hh);
hh = NULL;
}
- db_plugin->rollback (db_plugin->cls); /* just in case */
+ save ();
TALER_MERCHANTDB_plugin_unload (db_plugin);
db_plugin = NULL;
cfg = NULL;
@@ -220,8 +251,6 @@ credit_cb (
start_row = serial_id;
return GNUNET_OK;
}
- // FIXME: should also store serial_id,
- // at least "sometimes"...
qs = db_plugin->insert_transfer (db_plugin->cls,
instance_id,
exchange_url,
@@ -240,6 +269,7 @@ credit_cb (
start_row = serial_id;
return GNUNET_OK;
case MHD_HTTP_NO_CONTENT:
+ save ();
delay = GNUNET_TIME_UNIT_ZERO;
break;
default:
@@ -346,8 +376,21 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- // FIXME: extract 'start_row' from database somehow!
- // (Note: depends on bank account! => need new table!)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = db_plugin->select_wirewatch_progress (db_plugin->cls,
+ section,
+ &start_row);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to obtain wirewatch progress from database\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ progress_update = (0 != qs);
+ }
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&do_work,
NULL);