20#ifndef ORES_DQ_CORE_MESSAGING_FSM_HANDLER_HPP
21#define ORES_DQ_CORE_MESSAGING_FSM_HANDLER_HPP
25#include "ores.logging/make_logger.hpp"
26#include "ores.nats/domain/message.hpp"
27#include "ores.nats/service/client.hpp"
28#include "ores.database/domain/context.hpp"
29#include "ores.security/jwt/jwt_authenticator.hpp"
30#include "ores.service/messaging/handler_helpers.hpp"
31#include "ores.service/service/request_context.hpp"
32#include "ores.dq.api/messaging/fsm_protocol.hpp"
33#include "ores.dq.core/service/fsm_service.hpp"
35namespace ores::dq::messaging {
37using ores::service::messaging::reply;
38using ores::service::messaging::decode;
39using ores::service::messaging::error_reply;
43inline auto& fsm_handler_lg() {
44 static auto instance = ores::logging::make_logger(
45 "ores.dq.messaging.fsm_handler");
54 std::optional<ores::security::jwt::jwt_authenticator> verifier)
55 : nats_(nats), ctx_(
std::move(ctx)), verifier_(
std::move(verifier)) {}
58 BOOST_LOG_SEV(fsm_handler_lg(), debug) <<
"Handling " << msg.
subject;
59 auto req = decode<get_fsm_states_request>(msg);
61 BOOST_LOG_SEV(fsm_handler_lg(), warn)
62 <<
"Failed to decode: " << msg.
subject;
63 reply(nats_, msg, get_fsm_states_response{
64 .success =
false, .message =
"Failed to decode request"});
67 auto ctx_expected = ores::service::service::make_request_context(
68 ctx_, msg, verifier_);
70 error_reply(nats_, msg, ctx_expected.error());
73 service::fsm_service svc(*ctx_expected);
75 get_fsm_states_response resp;
76 if (req->machine_name.empty())
77 resp.states = svc.list_all_states();
79 resp.states = svc.list_states_for_machine(req->machine_name);
81 reply(nats_, msg, resp);
82 }
catch (
const std::exception& e) {
83 BOOST_LOG_SEV(fsm_handler_lg(), error)
84 << msg.
subject <<
" failed: " << e.what();
85 reply(nats_, msg, get_fsm_states_response{
86 .success =
false, .message = e.what()});
88 BOOST_LOG_SEV(fsm_handler_lg(), debug) <<
"Completed " << msg.
subject;
94 std::optional<ores::security::jwt::jwt_authenticator> verifier_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
A received NATS message.
Definition message.hpp:40
std::string subject
The subject the message was published to.
Definition message.hpp:44
NATS client: connection, pub/sub, request/reply, and JetStream.
Definition client.hpp:73