From c9f97591d4d55fc19bf3ceefa655e6fc7ed3ddc4 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 19 Dec 2021 18:45:38 +0100 Subject: [PATCH] Fix client page list query and apscheduler jobid --- app/client_mgt.py | 12 ++++++++++-- app/db_conn.py | 1 + app_client/main.py | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/client_mgt.py b/app/client_mgt.py index 9e607a9..c2712d5 100644 --- a/app/client_mgt.py +++ b/app/client_mgt.py @@ -20,7 +20,7 @@ def info(self): query = "select count(status) from events where client='%s' and status='KO';" %self.client count_ko = query_db(query)[0] #count_total = count_ok + count_ko - query = "select end_ts from events where client='%s' order by id desc limit 1;" %self.client + query = "select lastseen from clients where name='%s';" %self.client lastseen = query_db(query) query = "select joindate from clients where name='%s';" % self.client joindate = query_db(query) @@ -182,7 +182,7 @@ def list_clients_threshold(self): clientlist = query_db(query) return clientlist - def list_clients_page(self): + def list_clients_page_old(self): toregister = self.list_clists_to_register() #print(f"Client to register {toregister}") maxrows = 50000 @@ -233,6 +233,11 @@ def list_clients_page(self): res = query_db(query) return res + def list_clients_page(self): + query = ("SELECT name,status,joindate,threshold,ssh_key,lastseen from clients;") + res = query_db(query) + return res + def start_sync(self, start_ts, share, status="SYNCING"): self.start_ts = start_ts self.share = share @@ -252,3 +257,6 @@ def end_sync(self, start_ts, end_ts, status, sync_status, log): query = ("update events set status='%s', sync_status='%s', end_ts=%d, duration=%d, log='%s' where client='%s' and start_ts=%d") % (status, sync_status, end_ts, duration, log, self.client, start_ts) query_db(query) get_db().commit() + query = ("update clients set lastseen='%s' where name='%s'") % (end_ts, self.client) + query_db(query) + get_db().commit() diff --git a/app/db_conn.py b/app/db_conn.py index 7f97a05..3847737 100644 --- a/app/db_conn.py +++ b/app/db_conn.py @@ -30,6 +30,7 @@ share TEXT NOT NULL, threshold INTEGER NOT NULL, sync_status TEXT, + lastseen DATETIME, joindate DATETIME); """ diff --git a/app_client/main.py b/app_client/main.py index b9e9ee7..20d4e7c 100644 --- a/app_client/main.py +++ b/app_client/main.py @@ -94,7 +94,7 @@ def scheduler_sync(): } }) -scheduler.add_job(func=scheduler_sync, trigger="interval", seconds=int(sync_interval), next_run_time=datetime.now(), replace_existing=True) +scheduler.add_job(func=scheduler_sync, id="unison_sync_job", trigger="interval", seconds=int(sync_interval), next_run_time=datetime.now(), replace_existing=True) scheduler.start()