Search in sources :

Example 1 with TaskListMetadata

use of com.uber.cadence.TaskListMetadata in project cadence-client by uber-java.

the class ActivityPollTask method pollTask.

@Override
protected PollForActivityTaskResponse pollTask() throws TException {
    options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_COUNTER).inc(1);
    Stopwatch sw = options.getMetricsScope().timer(MetricsType.ACTIVITY_POLL_LATENCY).start();
    PollForActivityTaskRequest pollRequest = new PollForActivityTaskRequest();
    pollRequest.setDomain(domain);
    pollRequest.setIdentity(options.getIdentity());
    pollRequest.setTaskList(new TaskList().setName(taskList));
    if (options.getTaskListActivitiesPerSecond() > 0) {
        TaskListMetadata metadata = new TaskListMetadata();
        metadata.setMaxTasksPerSecond(options.getTaskListActivitiesPerSecond());
        pollRequest.setTaskListMetadata(metadata);
    }
    if (log.isDebugEnabled()) {
        log.debug("poll request begin: " + pollRequest);
    }
    PollForActivityTaskResponse result;
    try {
        result = service.PollForActivityTask(pollRequest);
    } catch (InternalServiceError | ServiceBusyError e) {
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_TRANSIENT_FAILED_COUNTER).inc(1);
        throw e;
    } catch (TException e) {
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_FAILED_COUNTER).inc(1);
        throw e;
    }
    if (result == null || result.getTaskToken() == null) {
        if (log.isDebugEnabled()) {
            log.debug("poll request returned no task");
        }
        options.getMetricsScope().counter(MetricsType.ACTIVITY_POLL_NO_TASK_COUNTER).inc(1);
        return null;
    }
    if (log.isTraceEnabled()) {
        log.trace("poll request returned " + result);
    }
    sw.stop();
    return result;
}
Also used : PollForActivityTaskRequest(com.uber.cadence.PollForActivityTaskRequest) TException(org.apache.thrift.TException) TaskListMetadata(com.uber.cadence.TaskListMetadata) TaskList(com.uber.cadence.TaskList) Stopwatch(com.uber.m3.tally.Stopwatch) PollForActivityTaskResponse(com.uber.cadence.PollForActivityTaskResponse) ServiceBusyError(com.uber.cadence.ServiceBusyError) InternalServiceError(com.uber.cadence.InternalServiceError)

Aggregations

InternalServiceError (com.uber.cadence.InternalServiceError)1 PollForActivityTaskRequest (com.uber.cadence.PollForActivityTaskRequest)1 PollForActivityTaskResponse (com.uber.cadence.PollForActivityTaskResponse)1 ServiceBusyError (com.uber.cadence.ServiceBusyError)1 TaskList (com.uber.cadence.TaskList)1 TaskListMetadata (com.uber.cadence.TaskListMetadata)1 Stopwatch (com.uber.m3.tally.Stopwatch)1 TException (org.apache.thrift.TException)1