From 4e1f62832ceeea8d0ea932c9661e438b5eadd519 Mon Sep 17 00:00:00 2001 From: Dmitry Rempel Date: Thu, 26 Nov 2026 13:38:38 +0300 Subject: [PATCH 1/2] feat: add method to get periodic task name --- core/include/userver/utils/periodic_task.hpp | 5 +++++ core/src/utils/periodic_task.cpp | 2 ++ core/src/utils/periodic_task_test.cpp | 8 +++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/include/userver/utils/periodic_task.hpp b/core/include/userver/utils/periodic_task.hpp index 8208779e3b4a..03c6f79213eb 100644 --- a/core/include/userver/utils/periodic_task.hpp +++ b/core/include/userver/utils/periodic_task.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -209,6 +210,10 @@ class PeriodicTask final { /// Get current settings. Note that they might become stale very quickly. Settings GetCurrentSettings() const; + /// @brief Returns the task name, or "" before a name is assigned. + /// The returned view remains valid until this object is destroyed. + std::string_view GetName() const noexcept; + private: class Impl; constexpr static std::size_t kSize = 448; diff --git a/core/src/utils/periodic_task.cpp b/core/src/utils/periodic_task.cpp index 74d785cc396a..d3a592e7fc11 100644 --- a/core/src/utils/periodic_task.cpp +++ b/core/src/utils/periodic_task.cpp @@ -310,6 +310,8 @@ PeriodicTask::Settings PeriodicTask::GetCurrentSettings() const { return *settings_ptr; } +std::string_view PeriodicTask::GetName() const noexcept { return impl_->GetName(); } + void StartPeriodicTask( PeriodicTask& periodic_task, std::string name, diff --git a/core/src/utils/periodic_task_test.cpp b/core/src/utils/periodic_task_test.cpp index 73248982e337..be0b944ddceb 100644 --- a/core/src/utils/periodic_task_test.cpp +++ b/core/src/utils/periodic_task_test.cpp @@ -21,7 +21,11 @@ namespace { const auto kSlowRatio = 10; } // namespace -UTEST(PeriodicTask, Noop) { const utils::PeriodicTask task; } +UTEST(PeriodicTask, Noop) { + const utils::PeriodicTask task; + + EXPECT_EQ(task.GetName(), ""); +} UTEST(PeriodicTask, StopWithoutStart) { utils::PeriodicTask task; @@ -32,8 +36,10 @@ UTEST(PeriodicTask, StartStop) { utils::PeriodicTask task("task", std::chrono::milliseconds(100), []() {}); EXPECT_TRUE(task.IsRunning()); + EXPECT_EQ(task.GetName(), "task"); task.Stop(); EXPECT_FALSE(task.IsRunning()); + EXPECT_EQ(task.GetName(), "task"); } UTEST(PeriodicTask, StartNoStop) { From 8d170724a24c3c364e60fe362967b12d65ff3e0a Mon Sep 17 00:00:00 2001 From: Dmitry Rempel Date: Thu, 26 Nov 2026 13:49:53 +0300 Subject: [PATCH 2/2] remove GetName --- core/include/userver/utils/periodic_task.hpp | 2 +- core/src/utils/periodic_task.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/include/userver/utils/periodic_task.hpp b/core/include/userver/utils/periodic_task.hpp index 03c6f79213eb..4a5b9cfeb334 100644 --- a/core/include/userver/utils/periodic_task.hpp +++ b/core/include/userver/utils/periodic_task.hpp @@ -212,7 +212,7 @@ class PeriodicTask final { /// @brief Returns the task name, or "" before a name is assigned. /// The returned view remains valid until this object is destroyed. - std::string_view GetName() const noexcept; + std::string_view GetName() const; private: class Impl; diff --git a/core/src/utils/periodic_task.cpp b/core/src/utils/periodic_task.cpp index d3a592e7fc11..1baf3a4c4e4d 100644 --- a/core/src/utils/periodic_task.cpp +++ b/core/src/utils/periodic_task.cpp @@ -310,7 +310,7 @@ PeriodicTask::Settings PeriodicTask::GetCurrentSettings() const { return *settings_ptr; } -std::string_view PeriodicTask::GetName() const noexcept { return impl_->GetName(); } +std::string_view PeriodicTask::GetName() const { return impl_->GetName(); } void StartPeriodicTask( PeriodicTask& periodic_task,