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 0AB121FF179 for ; Wed, 12 Nov 2025 10:42:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 51B8C1C4F8; Wed, 12 Nov 2025 10:42:48 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 12 Nov 2025 10:42:02 +0100 Message-ID: <20251112094203.112452-7-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251112094203.112452-1-l.wagner@proxmox.com> References: <20251112094203.112452-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762940506517 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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 Subject: [pdm-devel] [PATCH datacenter-manager 6/7] remote tasks: fetch/track PBS tasks X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Use the new API method bindings in pbs_client to fetch PBS task lists as well as to track the status of a task started by PDM. Signed-off-by: Lukas Wagner --- .../tasks/remote_tasks.rs | 98 ++++++++++++++----- 1 file changed, 72 insertions(+), 26 deletions(-) diff --git a/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs b/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs index e97f2a08..92f0f241 100644 --- a/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs +++ b/server/src/bin/proxmox-datacenter-api/tasks/remote_tasks.rs @@ -13,11 +13,11 @@ use pdm_api_types::{ RemoteUpid, }; use proxmox_section_config::typed::SectionConfigData; -use pve_api_types::{ListTasks, ListTasksResponse, ListTasksSource}; use server::{ - api::pve, + connection, parallel_fetcher::{NodeResults, ParallelFetcher}, + pbs_client, remote_tasks::{ self, task_cache::{NodeFetchSuccessMap, State, TaskCache, TaskCacheItem}, @@ -260,32 +260,51 @@ async fn fetch_tasks_from_single_node( remote: Remote, node: String, ) -> Result, Error> { + let since = context + .cutoff_timestamp(&remote.id, &node) + .unwrap_or_else(|| { + proxmox_time::epoch_i64() - (KEEP_OLD_FILES as u64 * ROTATE_AFTER) as i64 + }); + match remote.ty { RemoteType::Pve => { - let since = context - .cutoff_timestamp(&remote.id, &node) - .unwrap_or_else(|| { - proxmox_time::epoch_i64() - (KEEP_OLD_FILES as u64 * ROTATE_AFTER) as i64 - }); - - let params = ListTasks { - source: Some(ListTasksSource::Archive), + let params = pve_api_types::ListTasks { + source: Some(pve_api_types::ListTasksSource::Archive), since: Some(since), // If `limit` is not provided, we only receive 50 tasks limit: Some(MAX_TASKS_TO_FETCH), ..Default::default() }; - let client = pve::connect(&remote)?; + let client = connection::make_pve_client(&remote)?; let task_list = client .get_task_list(&node, params) .await? .into_iter() - .filter_map(|task| match map_pve_task(task, &remote.id) { - Ok(task) => Some(task), - Err(err) => { - log::error!("could not map PVE task: {err:#}"); + .map(|task| map_pve_task(task, remote.id.clone())) + .collect(); + + Ok(task_list) + } + RemoteType::Pbs => { + let params = pbs_client::ListTasks { + since: Some(since), + // If `limit` is not provided, we only receive 50 tasks + limit: Some(MAX_TASKS_TO_FETCH), + }; + + let client = connection::make_pbs_client(&remote)?; + + let task_list = client + .get_task_list(params) + .await? + .into_iter() + .filter_map(|task| { + if task.endtime.is_none() { + // We only care about finished tasks. + Some(map_pbs_task(task, remote.id.clone())) + } else { None } }) @@ -293,10 +312,6 @@ async fn fetch_tasks_from_single_node( Ok(task_list) } - RemoteType::Pbs => { - // TODO: Support PBS. - Ok(vec![]) - } } } @@ -426,22 +441,53 @@ async fn poll_single_tracked_task(remote: Remote, task: RemoteUpid) -> (RemoteUp (task, result) } RemoteType::Pbs => { - // TODO: Implement for PBS - (task, PollResult::RequestError) + let status = match server::api::pbs::tasks::get_task_status( + remote.id.clone(), + task.clone(), + false, + ) + .await + { + Ok(status) => status, + Err(err) => { + log::error!("could not get status from remote: {err:#}"); + return (task, PollResult::RequestError); + } + }; + + let result = if status.exitstatus.is_some() { + PollResult::Finished + } else { + PollResult::Running + }; + + (task, result) } } } -/// Map a `ListTasksResponse` to `TaskCacheItem` -fn map_pve_task(task: ListTasksResponse, remote: &str) -> Result { - let remote_upid: RemoteUpid = (remote.to_string(), task.upid.to_string()).try_into()?; +/// Map a `pve_api_types::ListTasksResponse` to `TaskCacheItem` +fn map_pve_task(task: pve_api_types::ListTasksResponse, remote: String) -> TaskCacheItem { + let remote_upid = RemoteUpid::new(remote, RemoteType::Pve, task.upid); - Ok(TaskCacheItem { + TaskCacheItem { upid: remote_upid, starttime: task.starttime, endtime: task.endtime, status: task.status, - }) + } +} + +/// Map a `pbs_api_types::TaskListItem` to `TaskCacheItem` +fn map_pbs_task(task: pbs_api_types::TaskListItem, remote: String) -> TaskCacheItem { + let remote_upid = RemoteUpid::new(remote, RemoteType::Pbs, task.upid); + + TaskCacheItem { + upid: remote_upid, + starttime: task.starttime, + endtime: task.endtime, + status: task.status, + } } /// Update task cache with results from tracked task polling & regular task fetching. -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel