public PollForDecisionTaskResponse poll()

in src/main/java/com/uber/cadence/internal/worker/WorkflowPollTask.java [67:131]


  public PollForDecisionTaskResponse poll() throws TException {
    metricScope.counter(MetricsType.DECISION_POLL_COUNTER).inc(1);
    Stopwatch sw = metricScope.timer(MetricsType.DECISION_POLL_LATENCY).start();

    PollForDecisionTaskRequest pollRequest = new PollForDecisionTaskRequest();
    pollRequest.setDomain(domain);
    pollRequest.setIdentity(identity);
    pollRequest.setBinaryChecksum(BinaryChecksum.getBinaryChecksum());

    TaskList tl = new TaskList().setName(taskList).setKind(taskListKind.toThrift());
    pollRequest.setTaskList(tl);

    if (log.isDebugEnabled()) {
      log.debug("poll request begin: " + pollRequest);
    }
    PollForDecisionTaskResponse result;
    try {
      result = service.PollForDecisionTask(pollRequest);
    } catch (InternalServiceError e) {
      metricScope
          .tagged(ImmutableMap.of(MetricsTag.CAUSE, INTERNAL_SERVICE_ERROR))
          .counter(MetricsType.DECISION_POLL_TRANSIENT_FAILED_COUNTER)
          .inc(1);
      throw e;
    } catch (ServiceBusyError e) {
      metricScope
          .tagged(ImmutableMap.of(MetricsTag.CAUSE, SERVICE_BUSY))
          .counter(MetricsType.DECISION_POLL_TRANSIENT_FAILED_COUNTER)
          .inc(1);
      throw e;
    } catch (TException e) {
      metricScope.counter(MetricsType.DECISION_POLL_FAILED_COUNTER).inc(1);
      throw e;
    }

    if (log.isDebugEnabled()) {
      log.debug(
          "poll request returned decision task: workflowType="
              + result.getWorkflowType()
              + ", workflowExecution="
              + result.getWorkflowExecution()
              + ", startedEventId="
              + result.getStartedEventId()
              + ", previousStartedEventId="
              + result.getPreviousStartedEventId()
              + (result.getQuery() != null
                  ? ", queryType=" + result.getQuery().getQueryType()
                  : ""));
    }

    if (result == null || result.getTaskToken() == null) {
      metricScope.counter(MetricsType.DECISION_POLL_NO_TASK_COUNTER).inc(1);
      return null;
    }

    Scope metricsScope =
        metricScope.tagged(
            ImmutableMap.of(MetricsTag.WORKFLOW_TYPE, result.getWorkflowType().getName()));
    metricsScope.counter(MetricsType.DECISION_POLL_SUCCEED_COUNTER).inc(1);
    metricsScope
        .timer(MetricsType.DECISION_SCHEDULED_TO_START_LATENCY)
        .record(Duration.ofNanos(result.getStartedTimestamp() - result.getScheduledTimestamp()));
    sw.stop();
    return result;
  }