code: def HasPendingTasks(self):
      
      with self._lock:
        self._AbandonInactiveProcessingTasks()
  
        if self._tasks_processing:
          return True
  
        # There are no tasks being processed, but we might be
        # waiting for some tasks to be merged.
        if self._HasTasksPendingMerge():
          return True
  
        # There are no tasks processing or pending merge, but there may
        # still be some waiting to be retried, so we check that.
        if self._HasTasksPendingRetry():
          return True
  
        # It is possible that a worker has processed a task and the foreman has
        # not been informed about it, since there is no feedback from the worker
        # when it pops a task from the queue.
  
        # If we believe all the workers are idle for longer than the task
        # inactive time (timeout) abandon all queued tasks. This ensures
        # that processing actually stops when the foreman never gets an
        # update from a worker.
  
        if self._tasks_queued:
          inactive_time = time.time() - self._TASK_INACTIVE_TIME
          inactive_time = int(inactive_time * definitions.MICROSECONDS_PER_SECOND)
  
          if self._latest_task_processing_time < inactive_time:
            self._AbandonQueuedTasks()
  
        if self._tasks_queued:
          return True
  
        if self._tasks_merging:
          return True
  
      # There are no tasks pending any work.
      return False
docs: Determines if there are tasks running or in need of retrying.
  
      Returns:
        bool: True if there are tasks that are active, ready to be merged or
            need to be retried.