private WorkerOp nextOp() {

      if (complete) {
        return WorkerOp.NO_OP;
      }

      if (isReady()) {
        if (needCommit) {
          return WorkerOp.COMMIT;
        } else if (needWindow) {
          return WorkerOp.WINDOW;
        } else if (needScheduler) {
          return WorkerOp.SCHEDULER;
        } else if (endOfStream && pendingEnvelopeQueue.isEmpty()) {
          return WorkerOp.END_OF_STREAM;
        } else if (shouldDrain && pendingEnvelopeQueue.isEmpty()) {
          return WorkerOp.DRAIN;
        } else if (!pendingEnvelopeQueue.isEmpty()) {
          return WorkerOp.PROCESS;
        }
      }
      return WorkerOp.NO_OP;
    }
Returns the next operation by this taskWorker
samza-core/src/main/java/org/apache/samza/container/RunLoop.java