From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E79611FF14C for ; Fri, 15 May 2026 09:46:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D59A2E3D3; Fri, 15 May 2026 09:46:43 +0200 (CEST) From: Thomas Lamprecht To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v3 02/12] pdm-client: add wait_for_local_task helper Date: Fri, 15 May 2026 09:43:12 +0200 Message-ID: <20260515074623.766766-3-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515074623.766766-1-t.lamprecht@proxmox.com> References: <20260515074623.766766-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: 1778831192299 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Message-ID-Hash: ZWOC4KXNOI7S7MRQO6K26ZU5QGFDAXN3 X-Message-ID-Hash: ZWOC4KXNOI7S7MRQO6K26ZU5QGFDAXN3 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). Signed-off-by: Thomas Lamprecht --- New in v3. lib/pdm-client/Cargo.toml | 3 +++ lib/pdm-client/src/lib.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 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 76b33ef8..cb5bb043 100644 --- a/lib/pdm-client/src/lib.rs +++ b/lib/pdm-client/src/lib.rs @@ -890,6 +890,36 @@ 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; + let running = body + .get("status") + .and_then(Value::as_str) + .map(|s| s == "running") + .unwrap_or(false); + if !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