From 59a59b50a078d7b74a5ba42446d2b5c1a1bf7514 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Sat, 02 Jun 2018 21:05:38 +0000 Subject: [PATCH] Pinging client even during work. Not the best solution but anyway.. --- tsclient.py | 14 ++++++++++---- devel.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/devel.py b/devel.py new file mode 100755 index 0000000..2a9fd7d --- /dev/null +++ b/devel.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +from tsclient import * +import signal + +#--- SIGINT and SIGTERM HANDLING --- +def signal_handler(signal,frame): + t.stop() + t.join() + print("Process ended with signal " +str(signal)) + sys.exit(signal) +#--- END SIGINT and SIGTERM---- + + + +signal.signal(signal.SIGINT, signal_handler) +signal.signal(signal.SIGTERM, signal_handler) + +t=ClientThread(conn_address='http://localhost:8000',update_seconds=100) +t.start() +#t.join() +#print("main") +while(True): + sleep(1000) diff --git a/tsclient.py b/tsclient.py index 6d2be9e..ed061b7 100755 --- a/tsclient.py +++ b/tsclient.py @@ -57,6 +57,8 @@ client_data={'client_id':cid} response=requests.post(addr+"/api/pingclient/", data=client_data) if(response.status_code==200): + client_data=json.loads(response.text) + return else: raise ValueError @@ -111,7 +113,7 @@ self.ip=get_ip() self.hostname=get_hostname() self.update_seconds=update_seconds - + self.max_client_ping_time_elapsed=250 def stop(self): self._stop_event.set() @@ -136,7 +138,7 @@ return True def run(self): - while(not self.isStopped()): + while(not self.isStopped()): #try to register try: cid=get_client_id(self.conn_address, self.ip, self.hostname, self.id) except: @@ -145,14 +147,14 @@ continue #print("Got CID. getting RID.") client_ping_time_elapsed=0 - while(not self.isStopped()): + while(not self.isStopped()): #successfully registered, now start pinging and searching for job try: (rid,tape,vtu,status)=get_run(self.conn_address,cid) except NameError: print("[{}] Could not get RID.".format(self.id)) self.sleep(10) client_ping_time_elapsed+=10 - if(client_ping_time_elapsed>=250): + if(client_ping_time_elapsed>=self.max_client_ping_time_elapsed): try: client_ping(self.conn_address,cid) except: @@ -232,6 +234,10 @@ self.p=None break self.sleep(self.update_seconds-1) + client_ping_time_elapsed+=self.update_seconds + if(client_ping_time_elapsed>self.max_client_ping_time_elapsed-self.update_seconds/2): + client_ping(self.conn_address,cid) + client_ping_time_elapsed=0 -- Gitblit v1.9.3