Example #1
0
 async def _get_latest_version_by_key(self, request):
     key = request.key
     namespace = request.namespace
     timeout_seconds = request.timeout_seconds
     if 0 == timeout_seconds:
         latest_version = self._query_latest_version_by_key(key, namespace)
         return notification_service_pb2.GetLatestVersionResponse(
             return_code=str(notification_service_pb2.ReturnStatus.SUCCESS),
             return_msg='',
             version=latest_version)
     else:
         start = time.time()
         latest_version = self._query_latest_version_by_key(key, namespace)
         async with self.write_condition:
             while time.time(
             ) - start < timeout_seconds and latest_version == 0:
                 try:
                     await asyncio.wait_for(
                         self.write_condition.wait(),
                         timeout_seconds - time.time() + start)
                     latest_version = self._query_latest_version_by_key(
                         key, namespace)
                 except asyncio.TimeoutError:
                     pass
         return notification_service_pb2.ListEventsResponse(
             return_code=str(notification_service_pb2.ReturnStatus.SUCCESS),
             return_msg='',
             version=latest_version)
Example #2
0
 def getLatestVersionByKey(self, request, context):
     try:
         return self._get_latest_version_by_key(request)
     except Exception as e:
         return notification_service_pb2.GetLatestVersionResponse(
             return_code=str(notification_service_pb2.ReturnStatus.ERROR),
             return_msg=str(e))