def batched_release(self, request): """Handles an incoming BatchedLeaseReleaseRequest. Batches are intended to save on RPCs only. The batched requests will not execute transactionally. """ # TODO(smut): Dedupe common logic in batched RPC handling. DEADLINE_SECS = 30 start_time = utils.utcnow() user = auth.get_current_identity().to_bytes() logging.info('Received BatchedLeaseReleaseRequest:\nUser: %s\n%s', user, request) responses = [] for request in request.requests: request_hash = models.LeaseRequest.generate_key(user, request).id() logging.info( 'Processing LeaseReleaseRequest:\nRequest hash: %s\n%s', request_hash, request, ) if (utils.utcnow() - start_time).seconds > DEADLINE_SECS: logging.warning( 'BatchedLeaseReleaseRequest exceeded enforced deadline: %s', DEADLINE_SECS, ) responses.append( rpc_messages.LeaseReleaseResponse( client_request_id=request.request_id, error=rpc_messages.LeaseReleaseRequestError. DEADLINE_EXCEEDED, request_hash=request_hash, )) else: try: responses.append( rpc_messages.LeaseReleaseResponse( client_request_id=request.request_id, error=self._release(request_hash), request_hash=request_hash, )) except ( datastore_errors.NotSavedError, datastore_errors.Timeout, runtime.apiproxy_errors.CancelledError, runtime.apiproxy_errors.DeadlineExceededError, runtime.apiproxy_errors.OverQuotaError, ) as e: logging.warning( 'Exception processing LeaseReleaseRequest:\n%s', e) responses.append( rpc_messages.LeaseReleaseResponse( client_request_id=request.request_id, error=rpc_messages.LeaseReleaseRequestError. TRANSIENT_ERROR, request_hash=request_hash, )) return rpc_messages.BatchedLeaseReleaseResponse(responses=responses)
def release(self, request): """Handles an incoming LeaseReleaseRequest.""" user = auth.get_current_identity().to_bytes() request_hash = models.LeaseRequest.generate_key(user, request).id() logging.info( 'Received LeaseReleaseRequest:\nUser: %s\nLeaseRequest: %s\n%s', user, request_hash, request, ) return rpc_messages.LeaseReleaseResponse( client_request_id=request.request_id, error=self._release(request_hash), request_hash=request_hash, )