use of com.google.api.services.cloudtasks.v2beta2.model.LeaseTasksRequest in project java-docs-samples by GoogleCloudPlatform.
the class PullQueue method pullTask.
// [END cloud_tasks_create_task]
// [START cloud_tasks_lease_and_acknowledge_task]
/**
* Pull a single task from a given queue and lease it for 10 minutes.
*/
private static Task pullTask(String project, String location, String queue) throws IOException {
// The name of the queue to use
String queueName = String.format("projects/%s/locations/%s/queues/%s", project, location, queue);
// Create the Cloud Tasks Client
CloudTasks client = createAuthorizedClient();
// Create the LeaseTasksRequest
LeaseTasksRequest request = new LeaseTasksRequest().setMaxTasks(1).setLeaseDuration("600s").setResponseView("FULL");
// Execute the request and return the pulled task
LeaseTasksResponse response = client.projects().locations().queues().tasks().lease(queueName, request).execute();
return response.getTasks().get(0);
}
Aggregations