From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 619651FF0B7 for ; Fri, 13 Nov 2026 16:13:52 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 20ECE216F4; Fri, 13 Nov 2026 16:10:05 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 39/55] notify: implement notification queue submitter Date: Fri, 13 Nov 2026 16:08:12 +0100 Message-ID: <20261113150828.756836-40-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113150828.756836-1-l.wagner@proxmox.com> References: <20261113150828.756836-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794582527966 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.205 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: 6KYW27H4ICWQUM3VWQAY5PIPEYT7XAR6 X-Message-ID-Hash: 6KYW27H4ICWQUM3VWQAY5PIPEYT7XAR6 X-MailFrom: l.wagner@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 VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Each product will be switched to a queue/worker approach, where each sender simply drops the notification in serialized form into a queue directory. Each notification has a unique UUID which is used as the filename, making filename collisions not an issue in practices. The new QueueSubmitter has a single method `submit`, which serialized the notification and atomically places it in the pre-existing queue directory. Signed-off-by: Lukas Wagner --- proxmox-notify/Cargo.toml | 1 + proxmox-notify/src/lib.rs | 3 ++ proxmox-notify/src/queue/mod.rs | 12 ++++++ proxmox-notify/src/queue/submitter.rs | 59 +++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 proxmox-notify/src/queue/mod.rs create mode 100644 proxmox-notify/src/queue/submitter.rs diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index e47912d11..a3de1a3fe 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -78,3 +78,4 @@ send-impl = [ pve-context = ["dep:proxmox-sys", "legacy-matchers"] pbs-context = ["dep:proxmox-sys", "legacy-matchers"] legacy-matchers = [] +queue-submitter = ["dep:proxmox-sys"] diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs index 4304e2977..ab5a929c1 100644 --- a/proxmox-notify/src/lib.rs +++ b/proxmox-notify/src/lib.rs @@ -28,6 +28,9 @@ mod send; #[cfg(feature = "send-impl")] pub use send::send; +#[cfg(feature = "queue-submitter")] +pub mod queue; + mod error; pub use error::Error; diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs new file mode 100644 index 000000000..59d5e12cd --- /dev/null +++ b/proxmox-notify/src/queue/mod.rs @@ -0,0 +1,12 @@ +use std::path::Path; + +use crate::Error; + +mod submitter; +pub use submitter::QueueSubmitter; + +fn fsync_queue_dir(queue_dir: &Path) -> Result<(), Error> { + std::fs::File::open(queue_dir) + .and_then(|dir| dir.sync_all()) + .map_err(|err| Error::other_with_source("fsync of queue directory failed", err)) +} diff --git a/proxmox-notify/src/queue/submitter.rs b/proxmox-notify/src/queue/submitter.rs new file mode 100644 index 000000000..01d81e959 --- /dev/null +++ b/proxmox-notify/src/queue/submitter.rs @@ -0,0 +1,59 @@ +//! Submission of notifications to the queue. + +use std::path::PathBuf; + +use proxmox_sys::fs::CreateOptions; + +use crate::{Error, Notification}; + +/// Writes notifications to the queue directory. +pub struct QueueSubmitter { + queue_dir: PathBuf, + create_options: CreateOptions, +} + +impl QueueSubmitter { + /// Create a new submitter for the queue directory `base_dir`. + /// + /// Queued notification files are created with `create_options`. + pub fn new>(base_dir: P, create_options: CreateOptions) -> Self { + Self { + queue_dir: base_dir.into(), + create_options, + } + } + + /// Add a notification to the queue. + /// + /// The file is written atomically and the queue directory is synced before returning. + pub fn submit(&self, notification: &Notification) -> Result<(), Error> { + let filename = format!("notification-{}", notification.id()); + let path = self.queue_dir.join(filename); + + let bytes = serde_json::to_vec(notification).map_err(|err| { + Error::other_with_source( + format!("failed to serialize notification {}", notification.id()), + err, + ) + })?; + + proxmox_sys::fs::replace_file(&path, &bytes, self.create_options, true).map_err(|err| { + Error::other_with_source( + format!( + "failed to store serialized notification {}", + notification.id() + ), + err, + ) + })?; + + super::fsync_queue_dir(&self.queue_dir)?; + + tracing::info!( + "submitted notification {} to notification queue", + notification.id() + ); + + Ok(()) + } +} -- 2.47.3