From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 16/17] server: api: tasks: move `spawn_aborted_on_shutdown()` to super module
Date: Thu, 11 Jun 2026 14:03:26 +0200 [thread overview]
Message-ID: <20260611120327.257523-17-s.sterz@proxmox.com> (raw)
In-Reply-To: <20260611120327.257523-1-s.sterz@proxmox.com>
so other new tasks can use it.
Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
Notes:
i wonder if we should create a trait here that handles this. we seem
to repeat quite a bit of code here and imo the pattern of:
`start_task` -> `run(_loop)` -> `run_single`
can be moved into a trait implementation and most tasks will
then only need to implement `run_single` and specify the interval for
the loop. here a small example of how this could be done (only threw
this together in a couple of minutes, so can be improved for sure):
```rs
pub trait ServerTask {
const INTERVAL: u64;
fn start() -> JoinHandle<()> {
tokio::spawn(async move {
let future = pin!(Self::run());
let abort_future = pin!(proxmox_daemon::shutdown_future());
futures::future::select(future, abort_future).await;
})
}
fn run() -> impl Future + Send + 'static {
async {
loop {
Self::run_once().await;
let delay_target = task_utils::next_aligned_instant(Self::INTERVAL);
tokio::time::sleep_until(tokio::time::Instant::from_std(delay_target)).await;
}
}
}
fn run_once() -> impl Future + Send + 'static;
}
struct CephTask;
impl ServerTask for CephTask {
const INTERVAL: u64 = 300;
#[tracing::instrument(skip_all, name = "ceph_detection")]
#[allow(refining_impl_trait)]
async fn run_once() {
if let Err(err) = server::ceph::sweep::sweep().await {
log::warn!("ceph auto-detection sweep failed: {err:#}");
}
}
}
```
.../tasks/ceph_detection.rs | 18 +-----------------
.../bin/proxmox-datacenter-api/tasks/mod.rs | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/server/src/bin/proxmox-datacenter-api/tasks/ceph_detection.rs b/server/src/bin/proxmox-datacenter-api/tasks/ceph_detection.rs
index fde171ad..990e15aa 100644
--- a/server/src/bin/proxmox-datacenter-api/tasks/ceph_detection.rs
+++ b/server/src/bin/proxmox-datacenter-api/tasks/ceph_detection.rs
@@ -6,29 +6,13 @@
//! daemon version), and refreshes the cached `ceph status` as a side effect so
//! the cluster-list overview keeps showing health without a live fetch.
-use std::future::Future;
-use std::pin::pin;
-
-use tokio::task::JoinHandle;
-
use server::task_utils;
/// How often to sweep all PVE remotes for Ceph clusters, in seconds.
const SWEEP_INTERVAL: u64 = 300;
-fn spawn_aborted_on_shutdown<F>(future: F) -> JoinHandle<()>
-where
- F: Future + Send + 'static,
-{
- tokio::spawn(async move {
- let future = pin!(future);
- let abort_future = pin!(proxmox_daemon::shutdown_future());
- futures::future::select(future, abort_future).await;
- })
-}
-
pub fn start_task() {
- spawn_aborted_on_shutdown(run());
+ super::spawn_aborted_on_shutdown(run());
}
async fn run() {
diff --git a/server/src/bin/proxmox-datacenter-api/tasks/mod.rs b/server/src/bin/proxmox-datacenter-api/tasks/mod.rs
index 34e4559d..2a05e9b3 100644
--- a/server/src/bin/proxmox-datacenter-api/tasks/mod.rs
+++ b/server/src/bin/proxmox-datacenter-api/tasks/mod.rs
@@ -4,3 +4,19 @@ pub mod ceph_detection;
pub mod remote_node_mapping;
pub mod remote_tasks;
pub mod remote_updates;
+
+use std::future::Future;
+use std::pin::pin;
+
+use tokio::task::JoinHandle;
+
+fn spawn_aborted_on_shutdown<F>(future: F) -> JoinHandle<()>
+where
+ F: Future + Send + 'static,
+{
+ tokio::spawn(async move {
+ let future = pin!(future);
+ let abort_future = pin!(proxmox_daemon::shutdown_future());
+ futures::future::select(future, abort_future).await;
+ })
+}
--
2.47.3
next prev parent reply other threads:[~2026-06-11 12:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 12:03 [RFC cluster/datacenter-manager/manager/proxmox 00/17] TLS Certificate Staging Shannon Sterz
2026-06-11 12:03 ` [PATCH cluster 01/17] setup: allow caller to provide the certificate filename Shannon Sterz
2026-06-11 12:03 ` [PATCH manager 02/17] bin/api: add a new staged certificate when renewing self-signed cert Shannon Sterz
2026-06-11 12:03 ` [PATCH manager 03/17] api: certificates: if node parameter is 'localhost' return local certs Shannon Sterz
2026-06-11 12:03 ` [PATCH proxmox 04/17] client: ignore certificate trust store validation result on fp option Shannon Sterz
2026-06-11 12:03 ` [PATCH proxmox 05/17] pve-api-types: expose certificates info endpoint Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 06/17] client: don't short-circuit on valid certificate when tls fp exists Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 07/17] client: allow users to update a changed fingerprint interactively Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 08/17] cli/api-types: move Fingerprint to common api type crate Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 09/17] server: connection: report mismatching fingerprint as untrusted on probe Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 10/17] ui: wizzard: add context if a provided fingerprint did not match remote Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 11/17] ui: wizzard: nodes page: always update fingerprints on user confirmation Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 12/17] pdm-api-types: implement ApiType for Fingerprint Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 13/17] pdm-api-types: add staged_fingerprints field to NodeUrl Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 14/17] server: remotes: lock remotes config when updating it Shannon Sterz
2026-06-11 12:03 ` [PATCH datacenter-manager 15/17] server: connection: rotate in staged fingerprints when encountering them Shannon Sterz
2026-06-11 12:03 ` Shannon Sterz [this message]
2026-06-11 12:03 ` [PATCH datacenter-manager 17/17] server: bin: api: tasks: add task to discover new staged certificates Shannon Sterz
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=20260611120327.257523-17-s.sterz@proxmox.com \
--to=s.sterz@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