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("/");
}
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);
}
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);
}
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);
}
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);
}
}
}
}
Aggregations