From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 920701FF135 for ; Thu, 02 Jul 2026 11:23:51 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C59122148B; Thu, 02 Jul 2026 11:23:49 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 04/15] task cache: rotate: align timestamp for new files to UTC midnight Date: Thu, 2 Jul 2026 11:22:47 +0200 Message-ID: <20260702092258.174740-5-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260702092258.174740-1-l.wagner@proxmox.com> References: <20260702092258.174740-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: 1782984189715 X-SPAM-LEVEL: Spam detection results: 0 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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: 2AF6EAUTG7K2EKPY4MFFTVYNPWJNL5NL X-Message-ID-Hash: 2AF6EAUTG7K2EKPY4MFFTVYNPWJNL5NL 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 Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This also requires to change the rotation check to an inclusive >=, otherwise we would only rotate after two days instead of every day. Signed-off-by: Lukas Wagner --- server/src/remote_tasks/refresh_task.rs | 23 ++++++++++++++++++++++- server/src/remote_tasks/task_cache.rs | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/src/remote_tasks/refresh_task.rs b/server/src/remote_tasks/refresh_task.rs index 68ef5a25..55d5694e 100644 --- a/server/src/remote_tasks/refresh_task.rs +++ b/server/src/remote_tasks/refresh_task.rs @@ -360,7 +360,13 @@ fn get_remotes_with_finished_tasks( /// /// Returns Ok(true) the cache's files were rotated. async fn rotate_cache(cache: TaskCache) -> Result { - tokio::task::spawn_blocking(move || cache.write()?.rotate(proxmox_time::epoch_i64())).await? + tokio::task::spawn_blocking(move || { + cache.write()?.rotate(align_timestamp( + proxmox_time::epoch_i64(), + super::ROTATE_AFTER as i64, + )) + }) + .await? } /// Apply the task cache journal. @@ -541,3 +547,18 @@ async fn update_task_cache( }) .await? } + +/// Align a UNIX timestamp to the specified interval. +fn align_timestamp(now: i64, interval: i64) -> i64 { + now - (now.rem_euclid(interval)) +} + +#[cfg(test)] +mod tests { + use crate::remote_tasks::refresh_task::align_timestamp; + + #[test] + fn test_align_timestamp() { + assert_eq!(align_timestamp(1782898009, 24 * 3600), 1782864000); + } +} diff --git a/server/src/remote_tasks/task_cache.rs b/server/src/remote_tasks/task_cache.rs index b5fc3b21..55aa8b70 100644 --- a/server/src/remote_tasks/task_cache.rs +++ b/server/src/remote_tasks/task_cache.rs @@ -285,7 +285,8 @@ impl WritableTaskCache { match archive_files.first() { Some(bound) => { - if now > bound.starttime && now - bound.starttime > self.cache.rotate_after as i64 { + if now > bound.starttime && now - bound.starttime >= self.cache.rotate_after as i64 + { start_new_file(&mut archive_files)?; } } -- 2.47.3