Skip to content

Commit

Permalink
Merge ff3c86d into 7f8997d
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed May 29, 2024
2 parents 7f8997d + ff3c86d commit aee3dd9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
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 succeed."
)
)
)]
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

0 comments on commit aee3dd9

Please sign in to comment.