refactor
Some checks are pending
BlockStorage/repertory/pipeline/head Build queued...
Blockstorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-09-15 14:38:30 -05:00
parent 643b5fbe7e
commit 8f2968d695

View File

@@ -882,96 +882,39 @@ void ui_server::start() {
}
};
auto should_launch{true};
lock_data ui_lock(provider_type::unknown, "ui");
auto res = ui_lock.grab_lock(1U);
if (res == lock_result::success) {
auto deadline{std::chrono::steady_clock::now() + 30s};
std::string host{"127.0.0.1"};
auto desired_port{config_->get_api_port()};
if (res != lock_result::success) {
notify_and_unlock(nonce_lock);
launch_ui();
return;
}
auto success{false};
while (not success && std::chrono::steady_clock::now() < deadline) {
success = server_.bind_to_port(host, desired_port);
if (success) {
break;
}
utils::error::raise_error(function_name,
utils::error::create_error_message({
"failed to bind",
"host",
host,
"port",
std::to_string(desired_port),
"error",
std::to_string(get_last_net_error()),
}));
std::this_thread::sleep_for(250ms);
}
auto deadline{std::chrono::steady_clock::now() + 30s};
std::string host{"127.0.0.1"};
auto desired_port{config_->get_api_port()};
auto success{false};
while (not success && std::chrono::steady_clock::now() < deadline) {
success = server_.bind_to_port(host, desired_port);
if (success) {
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();
notify_and_unlock(nonce_lock);
if (should_launch) {
launch_ui();
should_launch = false;
}
server_.listen_after_bind();
return;
break;
}
utils::error::raise_error(function_name,
utils::error::create_error_message({
"failed to bind",
"host",
host,
"port",
std::to_string(desired_port),
"error",
std::to_string(get_last_net_error()),
}));
std::this_thread::sleep_for(250ms);
}
if (not success) {
utils::error::raise_error(function_name,
utils::error::create_error_message({
"bind timeout (port in use)",
@@ -980,15 +923,63 @@ void ui_server::start() {
"port",
std::to_string(desired_port),
}));
should_launch = false;
}
notify_and_unlock(nonce_lock);
if (not should_launch) {
notify_and_unlock(nonce_lock);
return;
}
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();
}
void ui_server::stop() {