'Does the actual processing of the completed requests.'

def _ProcessCompletedRequests(self, notification):

    with queue_manager.QueueManager(token=self.token) as manager:
        for (request, _) in manager.FetchCompletedRequests(self.session_id, timestamp=(0, notification.timestamp)):
            if request.HasField('request'):
                manager.DeQueueClientRequest(request.client_id, request.request.task_id)
    if (not self.IsRunning()):
        self.queue_manager.DestroyFlowStates(self.session_id)
        return
    processing = []
    while True:
        try:
            for (request, responses) in self.queue_manager.FetchCompletedResponses(self.session_id, timestamp=(0, notification.timestamp)):
                if (request.id == 0):
                    continue
                if (not responses):
                    break
                if (request.id > self.context.next_processed_request):
                    stats.STATS.IncrementCounter('grr_response_out_of_order')
                    break
                if (request.id < self.context.next_processed_request):
                    self.queue_manager.DeleteRequest(request)
                    continue
                if (not responses):
                    continue
                if (len(responses) != responses[(-1)].response_id):
                    if (request.transmission_count < 5):
                        stats.STATS.IncrementCounter('grr_request_retransmission_count')
                        request.transmission_count += 1
                        self.ReQueueRequest(request)
                    break
                if self.IsRunning():
                    self.flow_obj.HeartBeat()
                    self.RunStateMethod(request.next_state, request, responses)
                else:
                    break
                self.queue_manager.DeleteRequest(request)
                self.context.next_processed_request += 1
                self.DecrementOutstandingRequests()
            if (not self.OutstandingRequests()):
                if (self.IsRunning() and (self.context.current_state != 'End')):
                    self.RunStateMethod('End')
            if (not self.OutstandingRequests()):
                stats.STATS.IncrementCounter('grr_flow_completed_count')
                stats.STATS.IncrementCounter('flow_completions', fields=[self.flow_obj.Name()])
                logging.debug('Destroying    session    %s(%s)    for    client    %s', self.session_id, self.flow_obj.Name(), self.runner_args.client_id)
                self.flow_obj.Terminate()
            return
        except queue_manager.MoreDataException:
            for event in processing:
                event.wait()
            self.FlushMessages()
            self.flow_obj.Flush()
            continue
        finally:
            for event in processing:
                event.wait()
