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 403A81FF179 for ; Wed, 15 Oct 2025 14:47:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E28E21B2AA; Wed, 15 Oct 2025 14:47:55 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 15 Oct 2025 14:47:04 +0200 Message-ID: <20251015124711.312943-6-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251015124711.312943-1-l.wagner@proxmox.com> References: <20251015124711.312943-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760532437265 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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 proxmox-datacenter-manager 05/12] unprivileged api daemon: tasks: add remote update refresh task 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" This commit adds a very simple refresh tasks that runs at relatively long interval. The task polls all remotes for available updates and puts the results in the update cache. Signed-off-by: Lukas Wagner --- server/src/bin/proxmox-datacenter-api/main.rs | 1 + .../bin/proxmox-datacenter-api/tasks/mod.rs | 1 + .../tasks/remote_updates.rs | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 server/src/bin/proxmox-datacenter-api/tasks/remote_updates.rs diff --git a/server/src/bin/proxmox-datacenter-api/main.rs b/server/src/bin/proxmox-datacenter-api/main.rs index c0f0e3a4..420a3b4d 100644 --- a/server/src/bin/proxmox-datacenter-api/main.rs +++ b/server/src/bin/proxmox-datacenter-api/main.rs @@ -377,6 +377,7 @@ async fn run(debug: bool) -> Result<(), Error> { tasks::remote_node_mapping::start_task(); resource_cache::start_task(); tasks::remote_tasks::start_task()?; + tasks::remote_updates::start_task()?; server.await?; log::info!("server shutting down, waiting for active workers to complete"); diff --git a/server/src/bin/proxmox-datacenter-api/tasks/mod.rs b/server/src/bin/proxmox-datacenter-api/tasks/mod.rs index a6b1f439..f4d1d3a1 100644 --- a/server/src/bin/proxmox-datacenter-api/tasks/mod.rs +++ b/server/src/bin/proxmox-datacenter-api/tasks/mod.rs @@ -1,2 +1,3 @@ pub mod remote_node_mapping; pub mod remote_tasks; +pub mod remote_updates; diff --git a/server/src/bin/proxmox-datacenter-api/tasks/remote_updates.rs b/server/src/bin/proxmox-datacenter-api/tasks/remote_updates.rs new file mode 100644 index 00000000..bd9e178d --- /dev/null +++ b/server/src/bin/proxmox-datacenter-api/tasks/remote_updates.rs @@ -0,0 +1,44 @@ +use anyhow::Error; + +use server::{remote_updates, task_utils}; + +const REFRESH_TIME: u64 = 6 * 3600; + +/// Start the remote task fetching task +pub fn start_task() -> Result<(), Error> { + tokio::spawn(async move { + let task_scheduler = std::pin::pin!(RemoteUpdateRefreshTask {}.run()); + let abort_future = std::pin::pin!(proxmox_daemon::shutdown_future()); + futures::future::select(task_scheduler, abort_future).await; + }); + + Ok(()) +} + +struct RemoteUpdateRefreshTask {} + +impl RemoteUpdateRefreshTask { + async fn run(self) { + loop { + self.refresh().await; + self.wait_for_refresh().await; + } + } + + async fn refresh(&self) { + if let Err(err) = self.do_refresh().await { + log::error!("could not refresh remote update cache: {err:#}"); + } + } + + async fn do_refresh(&self) -> Result<(), Error> { + let (config, _digest) = tokio::task::spawn_blocking(pdm_config::remotes::config).await??; + remote_updates::refresh_update_summary_cache(config.into_iter().map(|(_, r)| r).collect()) + .await + } + + async fn wait_for_refresh(&self) { + let instant = task_utils::next_aligned_instant(REFRESH_TIME); + tokio::time::sleep_until(instant.into()).await; + } +} -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel