Skip to content

Commit

Permalink
web server+client: /manager/probe_sync
Browse files Browse the repository at this point in the history
This fixes the following scenario:

```console
agama # cat rust/agama-lib/share/examples/profile_tw_gnome.json
{
  "software": {
    "patterns": [
      "gnome"
    ]
  }
}
agama # systemctl restart agama
agama # agama config load < rust/agama-lib/share/examples/profile_gnome.json
Anyhow(Backend call failed with status 400 and text '{"error":"Agama service error: Failed to find these patterns: [\"gnome\"]"}')
agama # systemctl restart agama
agama # PROBE_SYNC=1 agama config load < rust/agama-lib/share/examples/profile_gnome.json
agama #
```

Asynchronous probing results in a race(?) and an error when performing the
second PUT:

```
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: GET /api/software/config
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: PUT /api/software/config
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: POST /api/manager/probe
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: PUT /api/software/config
```
  • Loading branch information
mvidner committed Sep 3, 2024
1 parent 5ee5298 commit 5a53ebf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/agama-lib/src/manager/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ impl ManagerHTTPClient {
pub async fn probe(&self) -> Result<(), ServiceError> {
// BaseHTTPClient did not anticipate POST without request body
let empty_body: Vec<u8> = vec![];
if let Ok(value) = std::env::var("PROBE_SYNC") {
return if value == "1" {
self.client
.post_void("/manager/probe_sync", &empty_body)
.await
} else {
Ok(())
};
}
self.client.post_void("/manager/probe", &empty_body).await
}
}
15 changes: 15 additions & 0 deletions rust/agama-server/src/manager/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub async fn manager_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
let state = ManagerState { manager, dbus };
Ok(Router::new()
.route("/probe", post(probe_action))
.route("/probe_sync", post(probe_sync_action))
.route("/install", post(install_action))
.route("/finish", post(finish_action))
.route("/installer", get(installer_status))
Expand Down Expand Up @@ -134,6 +135,20 @@ async fn probe_action<'a>(State(state): State<ManagerState<'a>>) -> Result<(), E
Ok(())
}

/// Starts the probing process.
#[utoipa::path(
post,
path = "/probe_sync",
context_path = "/api/manager",
responses(
(status = 200, description = "Probing done.")
)
)]
async fn probe_sync_action(State(state): State<ManagerState<'_>>) -> Result<(), Error> {
state.manager.probe().await?;
Ok(())
}

/// Starts the probing process.
#[utoipa::path(
post,
Expand Down

0 comments on commit 5a53ebf

Please sign in to comment.