Search in sources :

Example 6 with TaskQueueQueryAndOwnTasksResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueue method queryAndOwnTasks.

@LatencyPercentiles(latency50th = 8)
public TaskQueueQueryAndOwnTasksResponse queryAndOwnTasks(Status status, TaskQueueQueryAndOwnTasksRequest request) {
    String queueName = request.getQueueName().toStringUtf8();
    validateQueueName(queueName);
    // getQueueByName will throw UNKNOWN_QUEUE if the queue does not exist.
    DevQueue queue = getQueueByName(queueName);
    if (queue.getMode() != Mode.PULL) {
        throw new ApiProxy.ApplicationException(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    }
    DevPullQueue pullQueue = (DevPullQueue) queue;
    List<TaskQueueAddRequest.Builder> results = pullQueue.queryAndOwnTasks(request.getLeaseSeconds(), request.getMaxTasks(), request.hasGroupByTag(), request.getTag().toByteArray());
    TaskQueueQueryAndOwnTasksResponse.Builder response = TaskQueueQueryAndOwnTasksResponse.newBuilder();
    for (TaskQueueAddRequest.Builder task : results) {
        TaskQueueQueryAndOwnTasksResponse.Task.Builder responseTask = response.addTaskBuilder().setTaskName(task.getTaskName()).setBody(task.getBody()).setEtaUsec(task.getEtaUsec());
        if (task.hasTag()) {
            responseTask.setTag(task.getTag());
        }
    // TODO: To keep track of retry count, we can replace TaskQueueAddRequest with
    // TaskQueueQueryTasksResponse to represent a task.
    }
    return response.build();
}
Also used : TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) ByteString(com.google.protobuf.ByteString) TaskQueueQueryAndOwnTasksResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Aggregations

TaskQueueQueryAndOwnTasksResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse)6 TaskQueueQueryAndOwnTasksRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest)5 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)4 Clock (com.google.appengine.tools.development.Clock)4 Status (com.google.appengine.tools.development.LocalRpcService.Status)4 Test (org.junit.Test)4 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)1 TaskQueueModifyTaskLeaseRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest)1 TaskQueueModifyTaskLeaseResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseResponse)1 LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)1 ApiConfig (com.google.apphosting.api.ApiProxy.ApiConfig)1 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1