use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.
the class RetryTask method retryTask.
public static void retryTask(String projectId, String locationId, String fooqueue, String barqueue, String bazqueue) throws Exception {
try (CloudTasksClient client = CloudTasksClient.create()) {
// TODO(developer): Uncomment these lines and replace with your values.
// String projectId = "your-project-id";
// String locationId = "us-central1";
// String fooqueue = "fooqueue";
// String barqueue = "barqueue";
// String bazqueue = "bazqueue";
LocationName parent = LocationName.of(projectId, locationId);
Duration retryDuration = Duration.newBuilder().setSeconds(2 * 60 * 60 * 24).build();
Duration min = Duration.newBuilder().setSeconds(10).build();
Duration max1 = Duration.newBuilder().setSeconds(200).build();
Duration max2 = Duration.newBuilder().setSeconds(300).build();
Queue foo = Queue.newBuilder().setName(QueueName.of(projectId, locationId, fooqueue).toString()).setRateLimits(RateLimits.newBuilder().setMaxDispatchesPerSecond(1.0)).setRetryConfig(RetryConfig.newBuilder().setMaxAttempts(7).setMaxRetryDuration(retryDuration)).build();
Queue bar = Queue.newBuilder().setName(QueueName.of(projectId, locationId, barqueue).toString()).setRateLimits(RateLimits.newBuilder().setMaxDispatchesPerSecond(1.0)).setRetryConfig(RetryConfig.newBuilder().setMinBackoff(min).setMaxBackoff(max1).setMaxDoublings(0)).build();
Queue baz = Queue.newBuilder().setName(QueueName.of(projectId, locationId, bazqueue).toString()).setRateLimits(RateLimits.newBuilder().setMaxDispatchesPerSecond(1.0)).setRetryConfig(RetryConfig.newBuilder().setMinBackoff(min).setMaxBackoff(max2).setMaxDoublings(3)).build();
Queue[] queues = new Queue[] { foo, bar, baz };
for (Queue queue : queues) {
Queue response = client.createQueue(parent, queue);
System.out.println(response);
}
}
}
use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.
the class CreateTask method createTask.
public static void createTask(String projectId, String locationId, String queueId) throws Exception {
try (CloudTasksClient client = CloudTasksClient.create()) {
// TODO(developer): Uncomment these lines and replace with your values.
// String projectId = "your-project-id";
// String locationId = "us-central1";
// String queueId = "default";
String key = "key";
// Construct the fully qualified queue name.
String queueName = QueueName.of(projectId, locationId, queueId).toString();
// Construct the task body.
Task taskParam = Task.newBuilder().setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder().setRelativeUri("/worker?key=" + key).setHttpMethod(HttpMethod.GET).build()).build();
Task taskPayload = Task.newBuilder().setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder().setBody(ByteString.copyFrom(key, Charset.defaultCharset())).setRelativeUri("/worker").setHttpMethod(HttpMethod.POST).build()).build();
// Send create task request.
Task[] tasks = new Task[] { taskParam, taskPayload };
for (Task task : tasks) {
Task response = client.createTask(queueName, task);
System.out.println(response);
}
}
}
use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.
the class DeleteQueue method deleteQueue.
public static void deleteQueue(String projectId, String locationId, String queueId) throws Exception {
try (CloudTasksClient client = CloudTasksClient.create()) {
// TODO(developer): Uncomment these lines and replace with your values.
// String projectId = "your-project-id";
// String locationId = "us-central1";
// String queueId = "foo";
// Construct the fully qualified queue name.
String queueName = QueueName.of(projectId, locationId, queueId).toString();
client.deleteQueue(queueName);
System.out.println("Queue Deleted.");
}
}
use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.
the class DeleteTask method deleteTask.
public static void deleteTask(String projectId, String locationId, String queueId, String taskId) throws Exception {
try (CloudTasksClient client = CloudTasksClient.create()) {
// TODO(developer): Uncomment these lines and replace with your values.
// String projectId = "your-project-id";
// String locationId = "us-central1";
// String queueId = "queue1";
// String taskId = "foo";
// Construct the fully qualified queue name.
String taskName = TaskName.of(projectId, locationId, queueId, taskId).toString();
client.deleteTask(taskName);
System.out.println("Task Deleted.");
}
}
use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.
the class UpdateQueue method updateQueue.
public static void updateQueue(String projectId, String locationId, String queueId) throws Exception {
try (CloudTasksClient client = CloudTasksClient.create()) {
// TODO(developer): Uncomment these lines and replace with your values.
// String projectId = "your-project-id";
// String locationId = "us-central1";
// String queueId = "queue-blue";
LocationName parent = LocationName.of(projectId, locationId);
Queue queueBlue = Queue.newBuilder().setName(QueueName.of(projectId, locationId, queueId).toString()).setRateLimits(RateLimits.newBuilder().setMaxDispatchesPerSecond(20.0).setMaxConcurrentDispatches(10)).build();
UpdateQueueRequest request = UpdateQueueRequest.newBuilder().setQueue(queueBlue).build();
Queue response = client.updateQueue(request);
System.out.println(response);
}
}
Aggregations