public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 05/12] unprivileged api daemon: tasks: add remote update refresh task
Date: Wed, 15 Oct 2025 14:47:04 +0200	[thread overview]
Message-ID: <20251015124711.312943-6-l.wagner@proxmox.com> (raw)
In-Reply-To: <20251015124711.312943-1-l.wagner@proxmox.com>

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 <l.wagner@proxmox.com>
---
 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


  parent reply	other threads:[~2025-10-15 12:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 12:46 [pdm-devel] [PATCH proxmox-datacenter-manager 00/12] add global remote update view Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 01/12] metric collection task: tests: add missing parameter for cluster_metric_export Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 02/12] pdm-api-types: add types for remote upgrade summary Lukas Wagner
2025-10-17 10:15   ` Shannon Sterz
2025-10-17 11:12     ` Lukas Wagner
2025-10-17 11:52     ` Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 03/12] remote updates: add cache for remote update availability Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 04/12] api: add API for retrieving/refreshing the remote update summary Lukas Wagner
2025-10-17  7:44   ` Lukas Wagner
2025-10-17 10:15   ` Shannon Sterz
2025-10-17 11:00     ` Lukas Wagner
2025-10-15 12:47 ` Lukas Wagner [this message]
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 06/12] pdm-client: add API methods for remote update summaries Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 07/12] pbs-client: add bindings for APT-related API calls Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 08/12] task cache: use separate functions for tracking PVE and PBS tasks Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 09/12] remote updates: add support for PBS remotes Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 10/12] api: add APT endpoints " Lukas Wagner
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 11/12] ui: add remote update view Lukas Wagner
2025-10-17 10:15   ` Shannon Sterz
2025-10-15 12:47 ` [pdm-devel] [PATCH proxmox-datacenter-manager 12/12] ui: show new remote update view in the 'Remotes' section Lukas Wagner
2025-10-17 10:15 ` [pdm-devel] [PATCH proxmox-datacenter-manager 00/12] add global remote update view Shannon Sterz
2025-10-17 12:14 ` [pdm-devel] superseded: " Lukas Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251015124711.312943-6-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal