diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-22 11:17:25 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-02-22 11:18:08 +0300 |
commit | d4900d85f7a5d791f89821713d02d3dd19361044 (patch) | |
tree | 4e7a1cc241d108c89779df9ec62f144a62937c17 /mod/database-module.hxx | |
parent | f5ed92e8dbdfd751276ebb054669ca649b28e43c (diff) |
Add support for tenant-associated service notifications
Diffstat (limited to 'mod/database-module.hxx')
-rw-r--r-- | mod/database-module.hxx | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/mod/database-module.hxx b/mod/database-module.hxx index f72ba83..910cb35 100644 --- a/mod/database-module.hxx +++ b/mod/database-module.hxx @@ -4,7 +4,7 @@ #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> @@ -14,6 +14,8 @@ 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. @@ -50,6 +52,25 @@ 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. + // + // 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). + // + void + 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. |