/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cloud/blockstore/libs/notify/impl/json_generator.cpp
69 строк
2 KB
Georg-0001
[Blockstore] Notify service refactoring to further support new notification format (#4007)
08 авг 2025, 12:30
Не верифицирован
08 авг 2025, 12:30
311fc3f
Код
Авторство
О чём код?
#include "json_generator.h" namespace NCloud::NBlockStore::NNotify { namespace { //////////////////////////////////////////////////////////////////////////////// template <typename T> concept TDiskEvent = std::is_same_v<T, TDiskError> || std::is_same_v<T, TDiskBackOnline>; //////////////////////////////////////////////////////////////////////////////// TStringBuf GetTemplateId(const TDiskError&) { return "nbs.nonrepl.error"; } TStringBuf GetTemplateId(const TDiskBackOnline&) { return "nbs.nonrepl.back-online"; } //////////////////////////////////////////////////////////////////////////////// void OutputEvent(IOutputStream& out, const TDiskEvent auto& event) { out << GetTemplateId(event) << " { " << event.DiskId << " }"; } //////////////////////////////////////////////////////////////////////////////// void FillData(const TDiskEvent auto& event, NJson::TJsonValue& data) { data["diskId"] = event.DiskId; } } // namespace //////////////////////////////////////////////////////////////////////////////// NJson::TJsonMap TJsonGenerator::Generate(const TNotification& data) { // TODO: Add Timestamp when time formatting will be supported // by Cloud Notify service NJson::TJsonMap v{ {"type", std::visit( [](const auto& event) { return GetTemplateId(event); }, data.Event)}, {"data", NJson::TJsonMap{ {"cloudId", data.CloudId}, {"folderId", data.FolderId}, }}}; if (!data.UserId.empty()) { v["userId"] = data.UserId; } else { v["cloudId"] = data.CloudId; } std::visit([&v](const auto& e) { FillData(e, v["data"]); }, data.Event); return v; } } // namespace NCloud::NBlockStore::NNotify