[pbs-devel] [PATCH proxmox-backup v2 6/9] syncjob: use JobState for determining when to run next scheduled sync

Dominik Csapak d.csapak at proxmox.com
Tue Aug 11 11:57:21 CEST 2020


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* use JobState enum matching and parse the upid for the starttime
 src/bin/proxmox-backup-proxy.rs | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 911f1057..b462c2ef 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -474,7 +474,7 @@ async fn schedule_datastore_prune() {
 async fn schedule_datastore_sync_jobs() {
 
     use proxmox_backup::{
-        config::{ sync::{self, SyncJobConfig}},
+        config::{ sync::{self, SyncJobConfig}, jobstate::JobState },
         tools::systemd::time::{ parse_calendar_event, compute_next_event },
     };
 
@@ -510,17 +510,28 @@ async fn schedule_datastore_sync_jobs() {
 
         let worker_type = "syncjob";
 
-        let last = match lookup_last_worker(worker_type, &job_id) {
-            Ok(Some(upid)) => {
+        let laststate = match JobState::try_read_or_create(worker_type, &job_id) {
+            Ok(state) => state,
+            Err(err) => {
+                eprintln!("could not load last state: {}", err);
+                continue;
+            }
+        };
+
+        let last = match laststate {
+            JobState::Created { time } => time,
+            JobState::Started { upid } | JobState::Finished { upid, .. } => {
+                let upid: crate::server::UPID = match upid.parse() {
+                    Ok(upid) => upid,
+                    Err(err) => {
+                        eprintln!("could not parse upid from state: {}", err);
+                        continue;
+                    }
+                };
                 if proxmox_backup::server::worker_is_active_local(&upid) {
                     continue;
                 }
                 upid.starttime
-            },
-            Ok(None) => 0,
-            Err(err) => {
-                eprintln!("lookup_last_job_start failed: {}", err);
-                continue;
             }
         };
 
-- 
2.20.1






More information about the pbs-devel mailing list