Search in sources :

Example 6 with Queue

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);
        }
    }
}
Also used : CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) Duration(com.google.protobuf.Duration) Queue(com.google.cloud.tasks.v2.Queue) LocationName(com.google.cloud.tasks.v2.LocationName)

Example 7 with Queue

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);
        }
    }
}
Also used : Task(com.google.cloud.tasks.v2.Task) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) ByteString(com.google.protobuf.ByteString)

Example 8 with Queue

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.");
    }
}
Also used : CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient)

Example 9 with Queue

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.");
    }
}
Also used : CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient)

Example 10 with Queue

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);
    }
}
Also used : CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) Queue(com.google.cloud.tasks.v2.Queue) UpdateQueueRequest(com.google.cloud.tasks.v2.UpdateQueueRequest) LocationName(com.google.cloud.tasks.v2.LocationName)

Aggregations

CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)10 Task (com.google.cloud.tasks.v2.Task)8 In (edu.princeton.cs.algs4.In)5 Queue (edu.princeton.cs.algs4.Queue)5 Queue (chapter1.section3.Queue)4 LocationName (com.google.cloud.tasks.v2.LocationName)3 Queue (com.google.cloud.tasks.v2.Queue)3 ByteString (com.google.protobuf.ByteString)3 Test (org.junit.jupiter.api.Test)3 HashSet (chapter3.section5.HashSet)2 AppEngineHttpRequest (com.google.cloud.tasks.v2.AppEngineHttpRequest)2 Transaction (edu.princeton.cs.algs4.Transaction)2 StringJoiner (java.util.StringJoiner)2 UnionFind (chapter1.section5.UnionFind)1 PriorityQueueResize (chapter2.section4.PriorityQueueResize)1 SeparateChainingHashTable (chapter3.section4.SeparateChainingHashTable)1 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)1 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)1 CreateTaskRequest (com.google.cloud.tasks.v2.CreateTaskRequest)1 QueueName (com.google.cloud.tasks.v2.QueueName)1