From 8d78589969cca7259d1d9d41b5805b0e2383b1f5 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 3 Jun 2020 16:34:07 +0200 Subject: [PATCH] improve display of 'next run' for sync jobs if the last sync job is too far in the past (or there was none at all for now) we run it at the next iteration, so we want to show that we now calculate the next_run by using either the real last endtime as time or 0 then in the frontend, we check if the next_run is < now and show 'pending' (we do it this way also for replication on pve) Signed-off-by: Dominik Csapak --- src/api2/admin/sync.rs | 26 +++++++++++--------------- www/config/SyncView.js | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index f6c8a720..ac2858f4 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -1,6 +1,5 @@ use anyhow::{Error}; use serde_json::Value; -use std::time::{SystemTime, UNIX_EPOCH}; use std::collections::HashMap; use proxmox::api::{api, ApiMethod, Router, RpcEnvironment}; @@ -51,25 +50,22 @@ pub fn list_sync_jobs( } } - let now = match SystemTime::now().duration_since(UNIX_EPOCH) { - Ok(epoch_now) => epoch_now.as_secs() as i64, - _ => 0i64, - }; - for job in &mut list { + let mut last = 0; + if let Some(task) = last_tasks.get(&job.id) { + job.last_run_upid = Some(task.upid_str.clone()); + if let Some((endtime, status)) = &task.state { + job.last_run_state = Some(String::from(status)); + job.last_run_endtime = Some(*endtime); + last = *endtime; + } + } + job.next_run = (|| -> Option { let schedule = job.schedule.as_ref()?; let event = parse_calendar_event(&schedule).ok()?; - compute_next_event(&event, now, false).ok() + compute_next_event(&event, last, false).ok() })(); - - if let Some(task) = last_tasks.get(&job.id) { - job.last_run_upid = Some(task.upid_str.clone()); - if let Some((endttime, status)) = &task.state { - job.last_run_state = Some(String::from(status)); - job.last_run_endtime = Some(*endttime); - } - } } rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into(); diff --git a/www/config/SyncView.js b/www/config/SyncView.js index 5c5d044a..634977c4 100644 --- a/www/config/SyncView.js +++ b/www/config/SyncView.js @@ -114,7 +114,19 @@ Ext.define('PBS.config.SyncJobView', { return ` ${gettext("Error")}:${value}`; }, - render_optional_timestamp: function(value) { + render_next_run: function(value, metadat, record) { + if (!value) return '-'; + + let now = new Date(); + let next = new Date(value*1000); + + if (next < now) { + return gettext('pending'); + } + return Proxmox.Utils.render_timestamp(value); + }, + + render_optional_timestamp: function(value, metadata, record) { if (!value) return '-'; return Proxmox.Utils.render_timestamp(value); }, @@ -237,7 +249,7 @@ Ext.define('PBS.config.SyncJobView', { header: gettext('Next Run'), sortable: true, minWidth: 200, - renderer: 'render_optional_timestamp', + renderer: 'render_next_run', dataIndex: 'next-run', }, {