Files
moloapp/src/operability/resilience/deadline.h
T
retoor 3c4334cec9 feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
2026-10-23 18:20:04 +02:00

42 lines
1.3 KiB
C++

// Deadline propagation for the X-Deadline-Ms header. Inbound absolute
// deadlines are converted to a remaining budget minus a 50 ms floor margin
// before forwarding, so downstream work never starts with a budget that is
// already expired. Production wires this into clients before send_inner.
#pragma once
#include <cstdint>
#include <optional>
#include <string>
namespace molo::common {
class Clock;
} // namespace molo::common
namespace molo::resilience {
class Deadline {
public:
explicit Deadline(::molo::common::Clock& clock);
Deadline(const Deadline&) = delete;
Deadline& operator=(const Deadline&) = delete;
// Parse an absolute epoch millis header value. Empty on malformed input.
static std::optional<std::int64_t> parse_header(const std::string& value);
// Format an absolute epoch millis header value.
static std::string format_header(std::int64_t absolute_ms);
// Remaining budget for outbound use: absolute minus now minus the 50 ms
// floor margin. Returns 0 when already expired or within the margin.
std::int64_t remaining_ms(std::int64_t absolute_ms) const;
// True when the absolute deadline leaves no usable budget.
bool expired(std::int64_t absolute_ms) const;
private:
::molo::common::Clock& clock_;
};
} // namespace molo::resilience