refactor
This commit is contained in:
@@ -146,9 +146,12 @@ auto load_config(std::string &cfg_file) -> app_config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (not utils::file::directory{cfg_dir}.create_directory()) {
|
if (not utils::file::directory{cfg_dir}.create_directory()) {
|
||||||
throw std::runtime_error(fmt::format("failed to create config dir|{}|{}",
|
throw utils::error::create_exception(
|
||||||
|
function_name, {
|
||||||
|
"failed to create config dir",
|
||||||
cfg_dir,
|
cfg_dir,
|
||||||
utils::get_last_error_code()));
|
std::to_string(utils::get_last_error_code()),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg_file = utils::path::combine(cfg_dir, {"monitarr.json"});
|
cfg_file = utils::path::combine(cfg_dir, {"monitarr.json"});
|
||||||
@@ -161,6 +164,17 @@ auto load_config(std::string &cfg_file) -> app_config {
|
|||||||
cfg.save(cfg_file);
|
cfg.save(cfg_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto iter = std::ranges::adjacent_find(
|
||||||
|
cfg.server_list,
|
||||||
|
[](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; });
|
||||||
|
if (iter != cfg.server_list.end()) {
|
||||||
|
throw utils::error::create_exception(function_name,
|
||||||
|
{
|
||||||
|
"duplicate server found",
|
||||||
|
iter->id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,12 @@ void data_db::open(std::string_view data_dir) {
|
|||||||
auto status = rocksdb::TransactionDB::Open(
|
auto status = rocksdb::TransactionDB::Open(
|
||||||
options, rocksdb::TransactionDBOptions{}, db_path, &ptr);
|
options, rocksdb::TransactionDBOptions{}, db_path, &ptr);
|
||||||
if (not status.ok()) {
|
if (not status.ok()) {
|
||||||
throw std::runtime_error(fmt::format("failed to open database|{}|{}",
|
throw utils::error::create_exception(function_name,
|
||||||
db_path, status.ToString()));
|
{
|
||||||
|
"failed to open database",
|
||||||
|
db_path,
|
||||||
|
status.ToString(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
db_ = std::shared_ptr<rocksdb::TransactionDB>(ptr);
|
db_ = std::shared_ptr<rocksdb::TransactionDB>(ptr);
|
||||||
|
|||||||
@@ -130,15 +130,20 @@ static void check_server(const server_cfg &server, data_db &state_db) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static auto load_db() -> data_db {
|
[[nodiscard]] static auto load_db() -> data_db {
|
||||||
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
auto data_dir = utils::get_environment_variable("MONITARR_DATA_DIR");
|
auto data_dir = utils::get_environment_variable("MONITARR_DATA_DIR");
|
||||||
if (data_dir.empty()) {
|
if (data_dir.empty()) {
|
||||||
data_dir = utils::path::combine(".", {"data"});
|
data_dir = utils::path::combine(".", {"data"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not utils::file::directory{data_dir}.create_directory()) {
|
if (not utils::file::directory{data_dir}.create_directory()) {
|
||||||
throw std::runtime_error(fmt::format("failed to create data dir|{}",
|
throw utils::error::create_exception(
|
||||||
|
function_name, {
|
||||||
|
"failed to create data dir",
|
||||||
data_dir,
|
data_dir,
|
||||||
utils::get_last_error_code()));
|
std::to_string(utils::get_last_error_code()),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
data_db state_db{};
|
data_db state_db{};
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
#include "usage_cmd.hpp"
|
#include "usage_cmd.hpp"
|
||||||
|
|
||||||
|
#include "utils/error.hpp"
|
||||||
|
|
||||||
namespace monitarr {
|
namespace monitarr {
|
||||||
auto usage_cmd() -> int {
|
auto usage_cmd() -> int {
|
||||||
fmt::println("usage:");
|
MONITARR_USES_FUNCTION_NAME();
|
||||||
fmt::println(" monitarr -b -i <index> -id <record id>");
|
|
||||||
fmt::println(" blocklist and search record id at configuration index");
|
utils::error::handle_info(
|
||||||
fmt::println(" monitarr -c");
|
function_name,
|
||||||
fmt::println(" display configuration");
|
"\n\nusage:\n"
|
||||||
fmt::println(" monitarr -l -i <index>");
|
" monitarr -b -i <index> -id <record id>\n"
|
||||||
fmt::println(" display server queue at configuration index");
|
" blocklist and search record id at configuration index\n"
|
||||||
fmt::println(" monitarr -r");
|
" monitarr -c\n"
|
||||||
fmt::println(" run monitarr server");
|
" display configuration\n"
|
||||||
fmt::println(" monitarr -s -i <index> -id <record id>");
|
" monitarr -l -i <index>\n"
|
||||||
fmt::println(" show record id details at configuration index");
|
" display server queue at configuration index\n"
|
||||||
|
" monitarr -r\n"
|
||||||
|
" run monitarr server\n"
|
||||||
|
" monitarr -s -i <index> -id <record id>\n"
|
||||||
|
" show record id details at configuration index\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user