Java Code Examples for com.google.appengine.api.taskqueue.Queue#deleteTask()
The following examples show how to use
com.google.appengine.api.taskqueue.Queue#deleteTask() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskqueueServlet.java From java-docs-samples with Apache License 2.0 | 6 votes |
private static String processTasks(List<TaskHandle> tasks, Queue q) { String payload; int numberOfDeletedTasks = 0; for (TaskHandle task : tasks) { payload = new String(task.getPayload()); output = String.format( "Processing: taskName='%s' payload='%s'", task.getName().toString(), payload.toString()); log.info(output.toString()); output = String.format("Deleting taskName='%s'", task.getName().toString()); log.info(output.toString()); // [START delete_task] q.deleteTask(task); // [END delete_task] numberOfDeletedTasks++; } if (numberOfDeletedTasks > 0) { message = "Processed and deleted " + numberOfTasksToLease + " tasks from the " + " task queue."; } else { message = "Task Queue has no tasks available for lease."; } return message; }
Example 2
Source File: TaskQueueServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
private void leaseAndDeleteTasks(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int numTasks = Integer.parseInt(req.getParameter("numTasks")); Double lease = Double.parseDouble(req.getParameter("lease")); String queue = req.getParameter("queue"); Queue q = QueueFactory.getQueue(queue); Boolean doDelete = Boolean.parseBoolean(req.getParameter("doDelete")); List<TaskHandle> tasks = q.leaseTasks(lease.intValue() * 1000, TimeUnit.MILLISECONDS, numTasks); for (TaskHandle task : tasks) { if (doDelete) { q.deleteTask(task.getName()); } } resp.getWriter().print(queue + "," + tasks.size()); }
Example 3
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testPullMultipleWithSameTag() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th1 = queue.add(withMethod(PULL).tag("barfoo2").payload("foobar").etaMillis(15000)); TaskHandle th2 = queue.add(withMethod(PULL).tag("barfoo2").payload("foofoo").etaMillis(10000)); try { List<TaskHandle> handles = waitOnFuture(queue.leaseTasksByTagAsync(30, TimeUnit.MINUTES, 100, "barfoo2")); assertEquals(2, handles.size()); Set<String> expectedTasks = taskHandlesToNameSet(th1, th2); Set<String> returnedTasks = taskHandleListToNameSet(handles); assertEquals(expectedTasks, returnedTasks); } finally { queue.deleteTask(th1); queue.deleteTask(th2); } }
Example 4
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testPullMultipleWithDiffTag() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th1 = queue.add(withMethod(PULL).tag("barfoo3").payload("foobar").etaMillis(15000)); TaskHandle th2 = queue.add(withMethod(PULL).tag("qwerty").payload("foofoo").etaMillis(10000)); TaskHandle th3 = queue.add(withMethod(PULL).tag("barfoo3").payload("foofoo").etaMillis(10000)); try { List<TaskHandle> handles = waitOnFuture(queue.leaseTasksByTagAsync(30, TimeUnit.MINUTES, 100, "barfoo3")); assertEquals(2, handles.size()); Set<String> expectedTasks = taskHandlesToNameSet(th1, th3); Set<String> returnedTasks = taskHandleListToNameSet(handles); assertEquals(expectedTasks, returnedTasks); handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, "qwerty"); assertEquals(1, handles.size()); Set<String> expectedTasks2 = taskHandlesToNameSet(th2); Set<String> returnedTasks2 = taskHandleListToNameSet(handles); assertEquals(expectedTasks2, returnedTasks2); } finally { queue.deleteTask(th1); queue.deleteTask(th2); queue.deleteTask(th3); } }
Example 5
Source File: SmokeTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testBasics() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); sync(2000L); TaskHandle th = queue.add(TaskOptions.Builder.withMethod(TaskOptions.Method.PULL).param("foo", "bar".getBytes())); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); Assert.assertFalse(handles.isEmpty()); Assert.assertEquals(1, handles.size()); TaskHandle lh = handles.get(0); Assert.assertEquals(th.getName(), lh.getName()); sync(5000L); } finally { queue.deleteTask(th); } }
Example 6
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullParams() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).param("foo", "bar").etaMillis(15000)); try { List<TaskHandle> handles = waitOnFuture(queue.leaseTasksAsync(30, TimeUnit.MINUTES, 100)); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 7
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullPayload() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).payload("foobar").etaMillis(15000)); try { List<TaskHandle> handles = waitOnFuture(queue.leaseTasksAsync(30, TimeUnit.MINUTES, 100)); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 8
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullWithTag() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).tag("barfoo1").etaMillis(15000)); try { List<TaskHandle> handles = waitOnFuture(queue.leaseTasksByTagAsync(30, TimeUnit.MINUTES, 100, "barfoo1")); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 9
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullWithGroupTag() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); String tag = "testPullWithGroupTag" + "_" + System.currentTimeMillis(); long currentTime = System.currentTimeMillis(); TaskHandle th1 = queue.add(withMethod(PULL).tag(tag).payload("foobar").etaMillis(currentTime)); TaskHandle th2 = queue.add(withMethod(PULL).tag(tag + "qwerty").payload("foofoo").etaMillis(currentTime + 1000)); TaskHandle th3 = queue.add(withMethod(PULL).tag(tag).payload("foofoo").etaMillis(currentTime + 2000)); sync(); try { LeaseOptions options = new LeaseOptions(LeaseOptions.Builder .withLeasePeriod(1000L, TimeUnit.SECONDS)) .countLimit(100) .groupByTag(); List<TaskHandle> handles = waitOnFuture(queue.leaseTasksAsync(options)); assertEquals(2, handles.size()); Set<String> expectedTasks = taskHandlesToNameSet(th1, th3); Set<String> returnedTasks = taskHandleListToNameSet(handles); assertEquals(expectedTasks, returnedTasks); } finally { queue.deleteTask(th1); queue.deleteTask(th2); queue.deleteTask(th3); } }
Example 10
Source File: PullAsyncTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testLeaseTasksOnlyReturnsSpecifiedNumberOfTasks() { Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th1 = queue.add(withMethod(PULL)); TaskHandle th2 = queue.add(withMethod(PULL)); sync(2000); try { int countLimit = 1; List<TaskHandle> handles = waitOnFuture(queue.leaseTasksAsync(10, TimeUnit.SECONDS, countLimit)); assertEquals(countLimit, handles.size()); } finally { queue.deleteTask(th1); queue.deleteTask(th2); } }
Example 11
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullParams() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).param("foo", "bar").etaMillis(15000)); sync(); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 12
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testPullPayload() throws Exception { final Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th = queue.add(withMethod(PULL).payload("foobar".getBytes()).etaMillis(15000)); sync(); try { List<TaskHandle> handles = queue.leaseTasks(30, TimeUnit.MINUTES, 100); assertFalse(handles.isEmpty()); TaskHandle lh = handles.get(0); assertEquals(th.getName(), lh.getName()); } finally { queue.deleteTask(th); } }
Example 13
Source File: PullTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testLeaseTasksOnlyReturnsSpecifiedNumberOfTasks() { Queue queue = QueueFactory.getQueue("pull-queue"); TaskHandle th1 = queue.add(withMethod(PULL)); TaskHandle th2 = queue.add(withMethod(PULL)); sync(); try { int countLimit = 1; List<TaskHandle> handles = queue.leaseTasks(10, TimeUnit.SECONDS, countLimit); assertEquals(countLimit, handles.size()); } finally { queue.deleteTask(th1); queue.deleteTask(th2); } }
Example 14
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 4 votes |
@Test(expected = IllegalStateException.class) public void testDeleteNonExist() { Queue nonExistQueue = QueueFactory.getQueue("nonExistQueue"); nonExistQueue.deleteTask("nonexist"); }