Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): avoid a long-lived probing request #1272

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions rust/agama-server/src/manager/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{

#[derive(Clone)]
pub struct ManagerState<'a> {
dbus: zbus::Connection,
manager: ManagerClient<'a>,
}

Expand Down Expand Up @@ -86,8 +87,8 @@ pub async fn manager_service(dbus: zbus::Connection) -> Result<Router, ServiceEr

let status_router = service_status_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;
let progress_router = progress_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;
let manager = ManagerClient::new(dbus).await?;
let state = ManagerState { manager };
let manager = ManagerClient::new(dbus.clone()).await?;
let state = ManagerState { manager, dbus };
Ok(Router::new()
.route("/probe", post(probe_action))
.route("/install", post(install_action))
Expand All @@ -100,16 +101,36 @@ pub async fn manager_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
}

/// Starts the probing process.
// The Probe D-Bus method is blocking and will not return until the probing is finished. To avoid a
// long-lived HTTP connection, this method returns immediately (with a 200) and runs the request on
// a separate task.
#[utoipa::path(
get,
path = "/probe",
context_path = "/api/manager",
responses(
(status = 200, description = "The probing process was started.")
(
status = 200,
description = "The probing was requested but there is no way to know whether it succeeded."
)
)
)]
async fn probe_action(State(state): State<ManagerState<'_>>) -> Result<(), Error> {
state.manager.probe().await?;
async fn probe_action<'a>(State(state): State<ManagerState<'a>>) -> Result<(), Error> {
let dbus = state.dbus.clone();
tokio::spawn(async move {
let result = dbus
.call_method(
Some("org.opensuse.Agama.Manager1"),
"/org/opensuse/Agama/Manager1",
Some("org.opensuse.Agama.Manager1"),
"Probe",
&(),
)
.await;
if let Err(error) = result {
tracing::error!("Could not start probing: {:?}", error);
}
});
Ok(())
}

Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed May 29 10:40:21 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- The HTTP request to perform a probing is not blocking anymore
(gh#openSUSE/agama#1272).

-------------------------------------------------------------------
Mon May 27 14:11:55 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down