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()>;
33 engine::TaskProcessor& task_processor,
34 std::shared_ptr<CoordinationClient> coordination_client,
35 std::string_view coordination_node,
36 std::string_view semaphore_name,
51 bool OwnsLock()
const noexcept;
53 friend void DumpMetric(
utils::statistics::Writer& writer,
const DistLockedWorker& worker);
56 void Run(
bool run_once);
58 engine::TaskProcessor& task_processor_;
59 const std::shared_ptr<CoordinationClient> coordination_client_;
60 const std::string coordination_node_;
61 const std::string semaphore_name_;
63 const Callback callback_;
65 utils::UniqueRef<impl::dist_lock::Statistics> stats_;
66 std::atomic<
bool> owns_lock_{
false};