diff options
Diffstat (limited to 'mod/database-module.hxx')
-rw-r--r-- | mod/database-module.hxx | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/mod/database-module.hxx b/mod/database-module.hxx index 06fc496..298afbf 100644 --- a/mod/database-module.hxx +++ b/mod/database-module.hxx @@ -1,20 +1,21 @@ // file : mod/database-module.hxx -*- C++ -*- -// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef MOD_DATABASE_MODULE_HXX #define MOD_DATABASE_MODULE_HXX -#include <odb/forward.hxx> // database +#include <odb/forward.hxx> // odb::core::database, odb::core::connection_ptr #include <libbrep/types.hxx> #include <libbrep/utility.hxx> #include <mod/module.hxx> -#include <mod/options.hxx> +#include <mod/module-options.hxx> namespace brep { + struct tenant_service; + // A handler that utilises the database. Specifically, it will retry the // request in the face of recoverable database failures (deadlock, loss of // connection, etc) up to a certain number of times. @@ -51,6 +52,26 @@ namespace brep virtual bool handle (request&, response&) = 0; + // Helpers. + // + + // Update the tenant-associated service state if the specified + // notification callback-returned function (expected to be not NULL) + // returns the new state data. Return the service state data, if updated, + // and nullopt otherwise. + // + // Specifically, start the database transaction, query the service state, + // and call the callback-returned function on this state. If this call + // returns the data string (rather than nullopt), then update the service + // state with this data and persist the change. Repeat all the above steps + // on the recoverable database failures (deadlocks, etc). + // + optional<string> + update_tenant_service_state ( + const odb::core::connection_ptr&, + const string& tid, + const function<optional<string> (const tenant_service&)>&); + protected: size_t retry_ = 0; // Max of all retries. |