| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -56,6 +56,28 @@ UploadItem = namedtuple('UploadItem', ['path', 'url', 'headers', 'created_at', ' | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					cur_upload_items = {} | 
					 | 
					 | 
					 | 
					cur_upload_items = {} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					class UploadQueueCache(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  params = Params() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  @staticmethod | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  def initialize(upload_queue): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    try: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      upload_queue_json = UploadQueueCache.params.get("AthenadUploadQueue") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      if upload_queue_json is not None: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        for item in json.loads(upload_queue_json): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          upload_queue.put(UploadItem(**item)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    except Exception: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      cloudlog.exception("athena.UploadQueueCache.initialize.exception") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  @staticmethod | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  def cache(upload_queue): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    try: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      items = [i._asdict() for i in upload_queue.queue if i.id not in cancelled_uploads] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      UploadQueueCache.params.put("AthenadUploadQueue", json.dumps(items)) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    except Exception: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					      cloudlog.exception("athena.UploadQueueCache.cache.exception") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def handle_long_poll(ws): | 
					 | 
					 | 
					 | 
					def handle_long_poll(ws): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  end_event = threading.Event() | 
					 | 
					 | 
					 | 
					  end_event = threading.Event() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -111,6 +133,7 @@ def upload_handler(end_event): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    try: | 
					 | 
					 | 
					 | 
					    try: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      cur_upload_items[tid] = upload_queue.get(timeout=1)._replace(current=True) | 
					 | 
					 | 
					 | 
					      cur_upload_items[tid] = upload_queue.get(timeout=1)._replace(current=True) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      if cur_upload_items[tid].id in cancelled_uploads: | 
					 | 
					 | 
					 | 
					      if cur_upload_items[tid].id in cancelled_uploads: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        cancelled_uploads.remove(cur_upload_items[tid].id) | 
					 | 
					 | 
					 | 
					        cancelled_uploads.remove(cur_upload_items[tid].id) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        continue | 
					 | 
					 | 
					 | 
					        continue | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -120,6 +143,7 @@ def upload_handler(end_event): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          cur_upload_items[tid] = cur_upload_items[tid]._replace(progress=cur / sz if sz else 1) | 
					 | 
					 | 
					 | 
					          cur_upload_items[tid] = cur_upload_items[tid]._replace(progress=cur / sz if sz else 1) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _do_upload(cur_upload_items[tid], cb) | 
					 | 
					 | 
					 | 
					        _do_upload(cur_upload_items[tid], cb) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        UploadQueueCache.cache(upload_queue) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.SSLError) as e: | 
					 | 
					 | 
					 | 
					      except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.SSLError) as e: | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        cloudlog.warning(f"athena.upload_handler.retry {e} {cur_upload_items[tid]}") | 
					 | 
					 | 
					 | 
					        cloudlog.warning(f"athena.upload_handler.retry {e} {cur_upload_items[tid]}") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -131,6 +155,8 @@ def upload_handler(end_event): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            current=False | 
					 | 
					 | 
					 | 
					            current=False | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          ) | 
					 | 
					 | 
					 | 
					          ) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          upload_queue.put_nowait(item) | 
					 | 
					 | 
					 | 
					          upload_queue.put_nowait(item) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					          UploadQueueCache.cache(upload_queue) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          cur_upload_items[tid] = None | 
					 | 
					 | 
					 | 
					          cur_upload_items[tid] = None | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          for _ in range(RETRY_DELAY): | 
					 | 
					 | 
					 | 
					          for _ in range(RETRY_DELAY): | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -248,6 +274,7 @@ def uploadFileToUrl(fn, url, headers): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  item = item._replace(id=upload_id) | 
					 | 
					 | 
					 | 
					  item = item._replace(id=upload_id) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  upload_queue.put_nowait(item) | 
					 | 
					 | 
					 | 
					  upload_queue.put_nowait(item) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  UploadQueueCache.cache(upload_queue) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return {"enqueued": 1, "item": item._asdict()} | 
					 | 
					 | 
					 | 
					  return {"enqueued": 1, "item": item._asdict()} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -280,8 +307,7 @@ def startLocalProxy(global_end_event, remote_ws_uri, local_port): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cloudlog.debug("athena.startLocalProxy.starting") | 
					 | 
					 | 
					 | 
					    cloudlog.debug("athena.startLocalProxy.starting") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    params = Params() | 
					 | 
					 | 
					 | 
					    dongle_id = Params().get("DongleId").decode('utf8') | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    dongle_id = params.get("DongleId").decode('utf8') | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    identity_token = Api(dongle_id).get_token() | 
					 | 
					 | 
					 | 
					    identity_token = Api(dongle_id).get_token() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    ws = create_connection(remote_ws_uri, | 
					 | 
					 | 
					 | 
					    ws = create_connection(remote_ws_uri, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                           cookie="jwt=" + identity_token, | 
					 | 
					 | 
					 | 
					                           cookie="jwt=" + identity_token, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -525,6 +551,7 @@ def backoff(retries): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def main(): | 
					 | 
					 | 
					 | 
					def main(): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  params = Params() | 
					 | 
					 | 
					 | 
					  params = Params() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  dongle_id = params.get("DongleId", encoding='utf-8') | 
					 | 
					 | 
					 | 
					  dongle_id = params.get("DongleId", encoding='utf-8') | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  UploadQueueCache.initialize(upload_queue) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  ws_uri = ATHENA_HOST + "/ws/v2/" + dongle_id | 
					 | 
					 | 
					 | 
					  ws_uri = ATHENA_HOST + "/ws/v2/" + dongle_id | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  api = Api(dongle_id) | 
					 | 
					 | 
					 | 
					  api = Api(dongle_id) | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |