13 std::unique_ptr<job> inner,
14 std::shared_ptr<circuit_breaker> cb)
15 :
job(
"protected_" + (inner ? inner->get_name() :
"unknown"))
16 , inner_(
std::move(inner))
29 "Circuit breaker is null");
40 if (!cb_->allow_request())
44 "Circuit breaker is open");
48 auto guard = cb_->make_guard();
52 auto result = inner_->do_work();
55 guard.record_success();
Represents a unit of work (task) to be executed, typically by a job queue.
auto get_name(void) const -> std::string
Retrieves the name of this job.
~protected_job() override
Destructor.
auto do_work() -> common::VoidResult override
Executes the wrapped job with circuit breaker protection.
auto get_name() const -> std::string
Gets the name of this job.
protected_job(std::unique_ptr< job > inner, std::shared_ptr< circuit_breaker > cb)
Constructs a protected job wrapper.
A template class representing either a value or an error.
bool is_ok() const noexcept
Checks if the result is successful.
Error codes and utilities for the thread system.
Core threading foundation of the thread system library.
common::VoidResult make_error_result(error_code code, const std::string &message="")
Create a common::VoidResult error from a thread::error_code.
Job wrapper integrating circuit breaker protection.