refactor
Some checks failed
Blockstorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
Blockstorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -77,6 +77,8 @@ private:
|
||||
mutable std::mutex test_mtx_;
|
||||
|
||||
private:
|
||||
void auto_start_mounts();
|
||||
|
||||
[[nodiscard]] auto data_directory_exists(provider_type prov,
|
||||
std::string_view name) const -> bool;
|
||||
|
||||
@@ -134,6 +136,8 @@ private:
|
||||
|
||||
void notify_and_unlock(unique_mutex_lock &nonce_lock);
|
||||
|
||||
void open_ui() const;
|
||||
|
||||
void removed_expired_nonces();
|
||||
|
||||
void set_key_value(provider_type prov, std::string_view name,
|
||||
|
@@ -278,6 +278,57 @@ ui_server::~ui_server() {
|
||||
E_CONSUMER_RELEASE();
|
||||
}
|
||||
|
||||
void ui_server::auto_start_mounts() const {
|
||||
std::thread([this]() {
|
||||
for (const auto &[prov, names] : config_->get_auto_start_list()) {
|
||||
for (const auto &name : names) {
|
||||
try {
|
||||
auto location = config_->get_mount_location(prov, name);
|
||||
if (location.empty()) {
|
||||
utils::error::raise_error(function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
"location is empty",
|
||||
}));
|
||||
} else if (not mount(prov, name, location)) {
|
||||
utils::error::raise_error(function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
"mount failed",
|
||||
}));
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(function_name, e,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
}));
|
||||
} catch (...) {
|
||||
utils::error::raise_error(function_name, "unknown error",
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}).join();
|
||||
}
|
||||
|
||||
auto ui_server::data_directory_exists(provider_type prov,
|
||||
std::string_view name) const -> bool {
|
||||
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
||||
@@ -800,6 +851,29 @@ void ui_server::notify_and_unlock(unique_mutex_lock &nonce_lock) {
|
||||
nonce_lock.unlock();
|
||||
}
|
||||
|
||||
void ui_server::open_ui() const {
|
||||
if (config_->get_launch_only()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
system(fmt::format(
|
||||
R"(start "Repertory Management Portal" "http://127.0.0.1:{}/ui")",
|
||||
config_->get_api_port())
|
||||
.c_str());
|
||||
#elif defined(__linux__)
|
||||
system(fmt::format(R"(xdg-open "http://127.0.0.1:{}/ui")",
|
||||
config_->get_api_port())
|
||||
.c_str());
|
||||
#elif defined(__APPLE__)
|
||||
system(
|
||||
fmt::format(R"(open "http://127.0.0.1:{}/ui")", config_->get_api_port())
|
||||
.c_str());
|
||||
#else
|
||||
build fails here
|
||||
#endif
|
||||
}
|
||||
|
||||
void ui_server::removed_expired_nonces() {
|
||||
unique_mutex_lock nonce_lock(nonce_mtx_);
|
||||
notify_and_unlock(nonce_lock);
|
||||
@@ -860,33 +934,11 @@ void ui_server::start() {
|
||||
nonce_thread_ =
|
||||
std::make_unique<std::thread>([this]() { removed_expired_nonces(); });
|
||||
|
||||
const auto launch_ui = [this]() {
|
||||
if (not config_->get_launch_only()) {
|
||||
#if defined(_WIN32)
|
||||
system(
|
||||
fmt::format(
|
||||
R"(start "Repertory Management Portal" "http://127.0.0.1:{}/ui")",
|
||||
config_->get_api_port())
|
||||
.c_str());
|
||||
#elif defined(__linux__)
|
||||
system(fmt::format(R"(xdg-open "http://127.0.0.1:{}/ui")",
|
||||
config_->get_api_port())
|
||||
.c_str());
|
||||
#elif defined(__APPLE__)
|
||||
system(fmt::format(R"(open "http://127.0.0.1:{}/ui")",
|
||||
config_->get_api_port())
|
||||
.c_str());
|
||||
#else
|
||||
build fails here
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
lock_data ui_lock(provider_type::unknown, "ui");
|
||||
auto res = ui_lock.grab_lock(1U);
|
||||
if (res != lock_result::success) {
|
||||
notify_and_unlock(nonce_lock);
|
||||
launch_ui();
|
||||
open_ui();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -927,58 +979,11 @@ void ui_server::start() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_start_mounts();
|
||||
open_ui();
|
||||
|
||||
notify_and_unlock(nonce_lock);
|
||||
|
||||
std::thread([this]() {
|
||||
for (const auto &[prov, names] : config_->get_auto_start_list()) {
|
||||
for (const auto &name : names) {
|
||||
try {
|
||||
auto location = config_->get_mount_location(prov, name);
|
||||
if (location.empty()) {
|
||||
utils::error::raise_error(function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
"location is empty",
|
||||
}));
|
||||
} else if (not mount(prov, name, location)) {
|
||||
utils::error::raise_error(function_name,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
"mount failed",
|
||||
}));
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(function_name, e,
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
}));
|
||||
} catch (...) {
|
||||
utils::error::raise_error(function_name, "unknown error",
|
||||
utils::error::create_error_message({
|
||||
"failed to auto-mount",
|
||||
"provider",
|
||||
provider_type_to_string(prov),
|
||||
"name",
|
||||
name,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}).join();
|
||||
|
||||
launch_ui();
|
||||
server_.listen_after_bind();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user