code: def CheckTaskToMerge(self, task):
      
      with self._lock:
        is_abandoned = task.identifier in self._tasks_abandoned
        is_processing = task.identifier in self._tasks_processing
        is_queued = task.identifier in self._tasks_queued
  
        if not is_queued and not is_processing and not is_abandoned:
          raise KeyError('Status of task {0:s} is unknown.'.format(
              task.identifier))
  
        return is_queued or is_processing or is_abandoned and not task.has_retry
docs: Checks if the task should be merged.
  
      Args:
        task (Task): task.
  
      Returns:
        bool: True if the task should be merged.
  
      Raises:
        KeyError: if the task was not queued, processing or abandoned.