| | |
| | | return (rid,tape,vtu,status) |
| | | else: |
| | | print(response.text) |
| | | if(response.status_code==400): |
| | | raise ValueError |
| | | else: |
| | | raise NameError |
| | | |
| | | |
| | | def ping_run(addr,cid, rid): |
| | |
| | | return |
| | | else: |
| | | raise ValueError |
| | | |
| | | def client_ping(addr,cid): |
| | | client_data={'client_id':cid} |
| | | response=requests.post(addr+"/api/pingclient/", data=client_data) |
| | | if(response.status_code==200): |
| | | return |
| | | else: |
| | | raise ValueError |
| | | |
| | | |
| | | |
| | | def send_error_report(addr,cid, rid,errcode): |
| | | client_data={'client_id':cid, 'run_id':rid, 'error_code':errcode} |
| | |
| | | self.id=subid |
| | | self.ip=get_ip() |
| | | self.hostname=get_hostname() |
| | | self.update_seconds=update_second |
| | | # self.subthreads=[] |
| | | self.update_seconds=update_seconds |
| | | |
| | | |
| | | def stop(self): |
| | | self._stop_event.set() |
| | |
| | | self.sleep(10) |
| | | continue |
| | | #print("Got CID. getting RID.") |
| | | client_ping_time_elapsed=0 |
| | | while(not self.isStopped()): |
| | | try: |
| | | (rid,tape,vtu,status)=get_run(self.conn_address,cid) |
| | | except: |
| | | except NameError: |
| | | print("[{}] Could not get RID.".format(self.id)) |
| | | self.sleep(10) |
| | | client_ping_time_elapsed+=10 |
| | | if(client_ping_time_elapsed>=250): |
| | | try: |
| | | client_ping(self.conn_address,cid) |
| | | except: |
| | | break |
| | | client_ping_time_elapsed=0 |
| | | #if you put break instead of continue, there is no need to ping client. And it is more robust... |
| | | continue |
| | | except ValueError: |
| | | print("[{}] Wrong CID? Getting new CID.".format(self.id)) |
| | | #self.sleep(10) |
| | | break |
| | | except: |
| | | print("[{}] Cannot connect. Server down? Retrying....".format(self.id)) |
| | | break |
| | | else: |
| | | #start separate thread with simulations. |