| | |
| | | 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 |
| | |
| | | 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() |
| | |
| | | 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: |
| | |
| | | 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: |
| | |
| | | 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 |
| | | |
| | | |
| | | |