From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 6416D1FF142 for ; Fri, 22 May 2026 10:52:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 473713431; Fri, 22 May 2026 10:52:08 +0200 (CEST) From: Thomas Lamprecht To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v4 02/10] pdm-client: add wait_for_local_task helper Date: Thu, 21 May 2026 21:20:30 +0200 Message-ID: <20260522085128.2678090-3-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260522085128.2678090-1-t.lamprecht@proxmox.com> References: <20260522085128.2678090-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1779439875262 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.521 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DATE_IN_PAST_12_24 1.049 Date: is 12 to 24 hours before Received: date DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Message-ID-Hash: 7XQLH6NPU4TJDBLZ6NGKWFA5LAF2ZIEM X-Message-ID-Hash: 7XQLH6NPU4TJDBLZ6NGKWFA5LAF2ZIEM X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: PDM-local worker tasks (those spawned via WorkerTask::spawn in the manager) return a UPID to the API caller, but the local task-status endpoint has no server-side wait=1 query like the per-remote PVE/PBS surface. A CLI that wants to surface the actual outcome rather than just print the UPID has to hand-roll a polling loop. Add a one-second-poll helper to consolidate that. Native-only since the loop uses tokio::time::sleep, so the WASM UI does not pull tokio into its dep tree (target-gated). Tested-by: Lukas Wagner Signed-off-by: Thomas Lamprecht --- Changes v3 -> 4: * Collapse the `running` test to a direct `body["status"].as_str() != Some("running")` indexing (Wolfgang). lib/pdm-client/Cargo.toml | 3 +++ lib/pdm-client/src/lib.rs | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/pdm-client/Cargo.toml b/lib/pdm-client/Cargo.toml index bb41b87b..a3f11059 100644 --- a/lib/pdm-client/Cargo.toml +++ b/lib/pdm-client/Cargo.toml @@ -22,6 +22,9 @@ proxmox-tfa = { workspace = true, features = [ "types" ] } pve-api-types = { workspace = true, features = [ "client" ] } pbs-api-types.workspace = true +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio = { workspace = true, features = [ "time" ] } + [features] default = [] hyper-client = [ "proxmox-client/hyper-client" ] diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs index c97c9db9..1cca65d8 100644 --- a/lib/pdm-client/src/lib.rs +++ b/lib/pdm-client/src/lib.rs @@ -904,6 +904,31 @@ impl PdmClient { Ok(self.0.get(&path).await?.expect_json()?.data) } + /// Block until a PDM-local worker task finishes; returns the final status payload. + /// + /// The local task-status endpoint (`/nodes/localhost/tasks/{upid}/status`) has no + /// server-side `wait=1` today, so the helper polls at one-second intervals; sub-second + /// tasks (e.g. an Apply Pending with an empty queue) settle on the first request. Once a + /// server-side wait surface lands this method becomes a single GET with no behaviour change + /// for callers. + /// + /// No built-in time bound; wrap in `tokio::time::timeout` if needed. Dropping the future + /// stops the client-side polling only - the server-side worker keeps running. + /// + /// Native-only: the polling loop relies on `tokio::time::sleep`, which is not available on + /// the wasm32 target the UI builds for. + #[cfg(not(target_arch = "wasm32"))] + pub async fn wait_for_local_task(&self, upid: &str) -> Result { + let path = format!("/api2/extjs/nodes/localhost/tasks/{upid}/status"); + loop { + let body: Value = self.0.get(&path).await?.expect_json()?.data; + if body["status"].as_str() != Some("running") { + return Ok(body); + } + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + } + pub async fn read_acl( &self, path: Option<&str>, -- 2.47.3