Samo Penic
2018-06-02 59a59b50a078d7b74a5ba42446d2b5c1a1bf7514
Pinging client even during work. Not the best solution but anyway..
1 files added
1 files modified
37 ■■■■ changed files
devel.py 23 ●●●●● patch | view | raw | blame | history
tsclient.py 14 ●●●● patch | view | raw | blame | history
devel.py
New file
@@ -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)
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