userver: userver/server/handlers/ping.hpp Source File
Loading...
Searching...
No Matches
ping.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/ping.hpp
4/// @brief @copybrief server::handlers::Ping
5
6#include <userver/components/state.hpp>
7#include <userver/server/handlers/http_handler_base.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace server::handlers {
12
13/// @ingroup userver_components userver_http_handlers
14///
15/// @brief Base class for handlers that returns HTTP 200 if the service
16/// is OK and able to process requests.
17///
18/// Uses components::State::IsAnyComponentInFatalState() to detect
19/// fatal state (can not process requests).
20///
21/// ## Static options of server::handlers::PingBase:
22///
23/// Options inherited from @ref server::handlers::HttpHandlerBase :
24/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/http_handler_base.md
25///
26/// Options inherited from @ref server::handlers::HandlerBase :
27/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/handler_base.md
28///
29/// Options inherited from @ref components::ComponentBase :
30/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
31///
32/// @ref userver_http_handlers
33class PingBase : public HttpHandlerBase {
34public:
35 PingBase(const components::ComponentConfig& config, const components::ComponentContext& component_context);
36
37 std::string HandleRequestThrow(const http::HttpRequest& request, request::RequestContext& context) const override;
38
39private:
40 const components::State components_;
41};
42
43/// @ingroup userver_components userver_http_handlers
44///
45/// @brief Ping handler implementation with warmup
46///
47/// ## Static options of server::handlers::Ping:
48/// @include{doc} scripts/docs/en/components_schema/ccore/src/server/handlers/ping.md
49///
50/// Options inherited from @ref server::handlers::HandlerBase :
51/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/handler_base.md
52///
53/// Options inherited from @ref components::ComponentBase :
54/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
55class Ping final : public PingBase {
56public:
57 Ping(const components::ComponentConfig& config, const components::ComponentContext& component_context);
58
59 /// @ingroup userver_component_names
60 /// @brief The default name of server::handlers::Ping
61 static constexpr std::string_view kName = "handler-ping";
62
63 std::string HandleRequestThrow(const http::HttpRequest& request, request::RequestContext& context) const override;
64
65 void OnAllComponentsLoaded() override;
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69private:
70 void AppendWeightHeaders(http::HttpResponse&) const;
71
72 std::chrono::steady_clock::time_point load_time_{};
73 std::chrono::seconds awacs_weight_warmup_time_{60};
74};
75
76} // namespace server::handlers
77
78template <>
79inline constexpr bool components::kHasValidate<server::handlers::Ping> = true;
80
81USERVER_NAMESPACE_END