Search in sources :

Example 11 with Queue

use of com.google.cloud.tasks.v2.Queue in project java-docs-samples by GoogleCloudPlatform.

the class Enqueue method doPost.

// Function creates Cloud Tasks from form submissions.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String key = request.getParameter("key");
    try (CloudTasksClient client = CloudTasksClient.create()) {
        // Construct the fully qualified queue name.
        String queueName = QueueName.of(projectId, locationId, "default").toString();
        // Construct the task body.
        Task task = Task.newBuilder().setAppEngineHttpRequest(AppEngineHttpRequest.newBuilder().setRelativeUri("/cloudtasks/worker?key=" + key).setHttpMethod(HttpMethod.POST).build()).build();
        // Add the task to the default queue.
        Task taskResponse = client.createTask(queueName, task);
        System.out.println("Task created: " + taskResponse.getName());
    }
    response.sendRedirect("/");
}
Also used : Task(com.google.cloud.tasks.v2.Task) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient)

Example 12 with Queue

use of com.google.cloud.tasks.v2.Queue in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_enqueueTasks_varargs.

@Test
void testSuccess_enqueueTasks_varargs() {
    Task task1 = cloudTasksUtils.createGetTask("/the/path", "myservice", params);
    Task task2 = cloudTasksUtils.createGetTask("/other/path", "yourservice", params);
    cloudTasksUtils.enqueue("test-queue", task1, task2);
    verify(mockClient).enqueue("project", "location", "test-queue", task1);
    verify(mockClient).enqueue("project", "location", "test-queue", task2);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 13 with Queue

use of com.google.cloud.tasks.v2.Queue in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_enqueueTask.

@Test
void testSuccess_enqueueTask() {
    Task task = cloudTasksUtils.createGetTask("/the/path", "myservice", params);
    cloudTasksUtils.enqueue("test-queue", task);
    verify(mockClient).enqueue("project", "location", "test-queue", task);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 14 with Queue

use of com.google.cloud.tasks.v2.Queue in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_enqueueTasks_iterable.

@Test
void testSuccess_enqueueTasks_iterable() {
    Task task1 = cloudTasksUtils.createGetTask("/the/path", "myservice", params);
    Task task2 = cloudTasksUtils.createGetTask("/other/path", "yourservice", params);
    cloudTasksUtils.enqueue("test-queue", ImmutableList.of(task1, task2));
    verify(mockClient).enqueue("project", "location", "test-queue", task1);
    verify(mockClient).enqueue("project", "location", "test-queue", task2);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 15 with Queue

use of com.google.cloud.tasks.v2.Queue in project AlgorithmsSolutions by Allenskoo856.

the class LookupIndex method main.

public static void main(String[] args) {
    In in = new In(args[0]);
    String sp = args[1];
    ST<String, Queue<String>> st = new ST<String, Queue<String>>();
    ST<String, Queue<String>> ts = new ST<String, Queue<String>>();
    while (in.hasNextLine()) {
        String[] a = in.readLine().split(sp);
        String key = a[0];
        for (int i = 1; i < a.length; i++) {
            String val = a[i];
            if (!st.contains(key)) {
                st.put(key, new Queue<String>());
            }
            if (!ts.contains(val)) {
                ts.put(val, new Queue<String>());
            }
            st.get(key).enqueue(val);
            ts.get(val).enqueue(key);
        }
    }
    while (!StdIn.isEmpty()) {
        String query = StdIn.readLine();
        if (st.contains(query)) {
            for (String s : st.get(query)) {
                StdOut.println(" " + s);
            }
        }
        if (ts.contains(query)) {
            for (String s : ts.get(query)) {
                StdOut.println(" " + s);
            }
        }
    }
}
Also used : ST(edu.princeton.cs.algs4.ST) StdIn(edu.princeton.cs.algs4.StdIn) In(edu.princeton.cs.algs4.In) Queue(com.jimmysun.algorithms.chapter1_3.Queue)

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