public boolean isDone(Operation operation) {
    Task task;
    try {
      task = scheduler.getTaskByName(operation.getName());
    } catch (ScheduleException se) {
      return false;
    }

    if (task.getStatus() == TaskStatus.SUSPEND) {
      return false;
    }

    TaskIDCounter counter = taskIdMapper.selectByPrimaryKey(task.getTaskid());
    if (counter == null || counter.getCounter() < operation.getNumber()) {
      return false;
    }
    InstanceID instanceID =
        new InstanceID(
            TaskID.forName(task.getTaskid()), counter.getCounter() - operation.getNumber() + 1);
    List<TaskAttempt> recentAttempts = getTaskAttemptByInstanceID(instanceID);
    if (recentAttempts == null || recentAttempts.size() == 0) {
      return false;
    }
    TaskAttempt history = recentAttempts.get(0);
    if (LOG.isDebugEnabled()) {
      LOG.debug("attempt : " + history.getAttemptid() + " status : " + history.getStatus());
    }
    int status = history.getStatus();

    // TODO bugs.
    if ((status == AttemptStatus.SUCCEEDED
        || status == AttemptStatus.FAILED
        || status == AttemptStatus.KILLED)) {
      if (history.getReturnvalue() != null && history.getReturnvalue() == operation.getValue()) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }