Github   Telegram
Loading...
Searching...
No Matches
components/component_sample_test.cpp
#include "component_sample_test.hpp"
#include <userver/dynamic_config/value.hpp>
namespace myservice::smth {
Component::Component(const components::ComponentConfig& config,
config_(
// Searching for some component to initialize members
.GetSource() // getting "client" from a component
) {
// Reading config values from static config
[[maybe_unused]] auto url = config["some-url"].As<std::string>();
const auto fs_tp_name = config["fs-task-processor"].As<std::string>();
// Starting a task on a separate task processor from config
auto& fs_task_processor = context.GetTaskProcessor(fs_tp_name);
utils::Async(fs_task_processor, "my-component/fs-work", [] { /*...*/ }).Get();
// ...
}
} // namespace myservice::smth
namespace myservice::smth {
Component::~Component() = default;
} // namespace myservice::smth
namespace myservice::smth {
namespace {
int ParseRuntimeCfg(const dynamic_config::DocsMap& docs_map) {
return docs_map.Get("SAMPLE_INTEGER_FROM_RUNTIME_CONFIG").As<int>();
}
} // namespace
int Component::DoSomething() const {
// Getting a snapshot of dynamic config.
const auto runtime_config = config_.GetSnapshot();
return runtime_config[kMyConfig];
}
} // namespace myservice::smth
namespace myservice::smth {
yaml_config::Schema Component::GetStaticConfigSchema() {
return yaml_config::MergeSchemas<components::LoggableComponentBase>(R"(
type: object
description: user component smth
additionalProperties: false
properties:
some-url:
type: string
description: url for something
fs-task-processor:
type: string
description: name of the task processor to do some bloking FS syscalls
)");
}
} // namespace myservice::smth