From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 8BD771FF15E
	for <inbox@lore.proxmox.com>; Tue, 28 Jan 2025 13:25:57 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B06AECC58;
	Tue, 28 Jan 2025 13:25:54 +0100 (CET)
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Tue, 28 Jan 2025 13:25:15 +0100
Message-Id: <20250128122520.167796-11-l.wagner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250128122520.167796-1-l.wagner@proxmox.com>
References: <20250128122520.167796-1-l.wagner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.135 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
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 10/15] remote tasks:
 allow to force-fetch latest tasks
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>

This one makes sense for a manual refresh button in the remote
task view.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 server/src/api/remote_tasks.rs |  9 +++++++--
 server/src/remote_tasks/mod.rs | 13 ++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/server/src/api/remote_tasks.rs b/server/src/api/remote_tasks.rs
index 05ce366..c55e15a 100644
--- a/server/src/api/remote_tasks.rs
+++ b/server/src/api/remote_tasks.rs
@@ -24,13 +24,18 @@ const SUBDIRS: SubdirMap = &sorted!([("list", &Router::new().get(&API_METHOD_LIS
             filters: {
                 type: TaskFilters,
                 flatten: true,
+            },
+            "force-refresh": {
+                description: "Force to fetch latest task data from remotes",
+                optional: true,
+                default: false,
             }
         },
     },
 )]
 /// Get the list of tasks for all remotes.
-async fn list_tasks(filters: TaskFilters) -> Result<Vec<TaskListItem>, Error> {
-    let tasks = remote_tasks::get_tasks(filters).await?;
+async fn list_tasks(filters: TaskFilters, force_refresh: bool) -> Result<Vec<TaskListItem>, Error> {
+    let tasks = remote_tasks::get_tasks(filters, force_refresh).await?;
 
     Ok(tasks)
 }
diff --git a/server/src/remote_tasks/mod.rs b/server/src/remote_tasks/mod.rs
index 3da6f25..171c8aa 100644
--- a/server/src/remote_tasks/mod.rs
+++ b/server/src/remote_tasks/mod.rs
@@ -26,7 +26,10 @@ const OVERLAP_S: i64 = 60;
 
 /// Get tasks for all remotes
 // FIXME: filter for privileges
-pub async fn get_tasks(filters: TaskFilters) -> Result<Vec<TaskListItem>, Error> {
+pub async fn get_tasks(
+    filters: TaskFilters,
+    force_refresh: bool,
+) -> Result<Vec<TaskListItem>, Error> {
     let (remotes, _) = pdm_config::remotes::config()?;
 
     let mut all_tasks = Vec::new();
@@ -45,14 +48,18 @@ pub async fn get_tasks(filters: TaskFilters) -> Result<Vec<TaskListItem>, Error>
     // a task's endtime, which is only returned by
     // /nodes/<node>/tasks...
     // Room for improvements in the future.
-    let force_refresh_remotes = get_remotes_with_finished_tasks();
+    let remotes_with_finished_tasks = get_remotes_with_finished_tasks();
 
     let now = proxmox_time::epoch_i64();
     for (remote_name, remote) in &remotes.sections {
         let last_fetched = cache.get_last_fetched(remote_name).unwrap_or(0);
         let diff = now - last_fetched;
 
-        if diff > REFRESH_EVERY_S || diff < 0 || force_refresh_remotes.contains(remote_name) {
+        let data_too_old = diff > REFRESH_EVERY_S;
+        let clock_jumped_backwards = diff < 0;
+        let forced_by_finished_task = remotes_with_finished_tasks.contains(remote_name);
+
+        if data_too_old || clock_jumped_backwards || forced_by_finished_task || force_refresh {
             // Add some overlap so that we for sure fetch every task - duplicates
             // are remove when adding the tasks to the cache.
             let fetch_since =
-- 
2.39.5



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel