diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-04-25 09:57:15 +0300 |
---|---|---|
committer | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-04-25 09:57:15 +0300 |
commit | 0fbef0f9c08b91f3238020e5d13c6ad2c232e814 (patch) | |
tree | 53cf1dd87b7ebe56f186746d7e4551e49975dc74 | |
parent | 46eb7d3ce8b0b25249e4acb986fe1e847f63d8ee (diff) | |
download | ydb-0fbef0f9c08b91f3238020e5d13c6ad2c232e814.tar.gz |
error message into conveyor task
-rw-r--r-- | ydb/core/tx/conveyor/service/worker.cpp | 2 | ||||
-rw-r--r-- | ydb/core/tx/conveyor/usage/abstract.cpp | 22 | ||||
-rw-r--r-- | ydb/core/tx/conveyor/usage/abstract.h | 19 |
3 files changed, 40 insertions, 3 deletions
diff --git a/ydb/core/tx/conveyor/service/worker.cpp b/ydb/core/tx/conveyor/service/worker.cpp index caba610a3a..466be3d047 100644 --- a/ydb/core/tx/conveyor/service/worker.cpp +++ b/ydb/core/tx/conveyor/service/worker.cpp @@ -7,7 +7,7 @@ void TWorker::HandleMain(TEvInternal::TEvNewTask::TPtr& ev) { if (workerTask.GetTask()->Execute()) { TBase::Sender<TEvInternal::TEvTaskProcessedResult>(workerTask.GetOwnerId(), workerTask.GetTask()).SendTo(ev->Sender); } else { - TBase::Sender<TEvInternal::TEvTaskProcessedResult>(workerTask.GetOwnerId(), "cannot execute task").SendTo(ev->Sender); + TBase::Sender<TEvInternal::TEvTaskProcessedResult>(workerTask.GetOwnerId(), workerTask.GetTask()->GetErrorMessage()).SendTo(ev->Sender); } } diff --git a/ydb/core/tx/conveyor/usage/abstract.cpp b/ydb/core/tx/conveyor/usage/abstract.cpp index 42737a8e14..1d2eaeffcd 100644 --- a/ydb/core/tx/conveyor/usage/abstract.cpp +++ b/ydb/core/tx/conveyor/usage/abstract.cpp @@ -1,5 +1,27 @@ #include "abstract.h" +#include <util/generic/yexception.h> +#include <util/string/builder.h> namespace NKikimr::NConveyor { +bool ITask::Execute() { + bool result = false; + try { + result = DoExecute(); + if (!result) { + if (!ErrorMessage) { + ErrorMessage = "cannot execute task (not specified error message)"; + } + } + } catch (...) { + TStringBuilder sbLocalMessage; + sbLocalMessage << "exception: " << CurrentExceptionMessage(); + if (!ErrorMessage) { + ErrorMessage = sbLocalMessage; + } else { + ErrorMessage += sbLocalMessage; + } + } + return result; +} } diff --git a/ydb/core/tx/conveyor/usage/abstract.h b/ydb/core/tx/conveyor/usage/abstract.h index 5901809330..fa60859083 100644 --- a/ydb/core/tx/conveyor/usage/abstract.h +++ b/ydb/core/tx/conveyor/usage/abstract.h @@ -1,17 +1,32 @@ #pragma once #include <memory> +#include <ydb/library/accessor/accessor.h> +#include <util/generic/string.h> namespace NKikimr::NConveyor { class ITask { +private: + TString ErrorMessage; protected: + ITask& SetErrorMessage(const TString& message) { + ErrorMessage = message; + return *this; + } virtual bool DoExecute() = 0; public: using TPtr = std::shared_ptr<ITask>; virtual ~ITask() = default; - bool Execute() { - return DoExecute(); + + bool HasError() const { + return !!ErrorMessage; } + + const TString& GetErrorMessage() const { + return ErrorMessage; + } + + bool Execute(); }; } |