Samo Penic
2018-06-02 59a59b50a078d7b74a5ba42446d2b5c1a1bf7514
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