11#include <userver/engine/task/task_with_result.hpp>
12#include <userver/utils/not_null.hpp>
13#include <userver/utils/statistics/fwd.hpp>
14#include <userver/ydb/coordination.hpp>
15#include <userver/ydb/dist_lock/settings.hpp>
17USERVER_NAMESPACE_BEGIN
21namespace impl::dist_lock {
28class DistLockedWorker
final {
30 using Callback = std::function<
void()>;
32 DistLockedWorker(engine::TaskProcessor& task_processor,
33 std::shared_ptr<CoordinationClient> coordination_client,
34 std::string_view coordination_node,
48 bool OwnsLock()
const noexcept;
50 friend void DumpMetric(utils::statistics::Writer& writer,
51 const DistLockedWorker& worker);
54 void Run(
bool run_once);
56 engine::TaskProcessor& task_processor_;
57 const std::shared_ptr<CoordinationClient> coordination_client_;
58 const std::string coordination_node_;
59 const std::string semaphore_name_;
61 const Callback callback_;
63 utils::UniqueRef<impl::dist_lock::Statistics> stats_;
64 std::atomic<
bool> owns_lock_{
false};