com.google.appengine.api.taskqueue.TaskHandle Java Examples
The following examples show how to use
com.google.appengine.api.taskqueue.TaskHandle.
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: AppEngineTaskQueueTest.java From appengine-pipelines with Apache License 2.0 | 6 votes |
public void testEnqueueLargeBatchTasks() { AppEngineTaskQueue queue = new AppEngineTaskQueue(); int batchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE * 2 + 10; List<Task> tasks = new ArrayList<>(batchSize); for (int i = 0; i < batchSize; i++) { Task task = createTask(); tasks.add(task); } List<TaskHandle> handles = queue.addToQueue(tasks); assertEquals(tasks.size(), handles.size()); for (int i = 0; i < tasks.size(); i++) { assertEquals(tasks.get(i).getName(), handles.get(i).getName()); } handles = queue.addToQueue(tasks); assertEquals(0, handles.size()); }
Example #2
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testEtaMillis() { String tag = "testEtaMillis_" + getTimeStampRandom(); queue.add(withMethod(PULL).etaMillis(System.currentTimeMillis() + 10000).tag(tag)); sync(5000); // Give tasks a chance to become available. List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1)); assertEquals(0, tasks.size()); sync(10000); tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag.getBytes()).leasePeriod(1, TimeUnit.SECONDS).countLimit(1)); assertEquals(1, tasks.size()); queue.deleteTask(tasks); }
Example #3
Source File: PullQueueAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testCountdownMillis() { String tag = "testCountdownMillis_" + getTimeStampRandom(); waitOnFuture(queue.addAsync(TaskOptions.Builder.withMethod(PULL).countdownMillis(15000).tag(tag))); sleep(5000); // Give tasks a chance to become available. List<TaskHandle> tasks = waitOnFuture(queue.leaseTasksAsync(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1))); assertEquals(0, tasks.size()); sleep(15000); tasks = waitOnFuture(queue.leaseTasksAsync(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1))); assertEquals(1, tasks.size()); waitOnFuture(queue.deleteTaskAsync(tasks)); }
Example #4
Source File: PullQueueAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testLeaseExpiration() { String groupTag = "testLeaseExpiration"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); deleteOnTearDownTags.add(taskBaseName); int count = 1; List<TaskHandle> taskList = addTasks(count, taskBaseName, groupTag, "nada"); long leaseDuration = 1000; LeaseOptions options = LeaseOptions.Builder .withTag(groupTag) .countLimit(count) .leasePeriod(leaseDuration, TimeUnit.MILLISECONDS); List<TaskHandle> tasks = waitOnFuture(queue.leaseTasksAsync(options)); assertEquals(count, tasks.size()); sleep(leaseDuration + 1000); // wait for lease to expire List<TaskHandle> tasksAfterExpire = waitOnFuture(queue.leaseTasksAsync(options)); // expired, so it should be available for lease. assertEquals(count, tasksAfterExpire.size()); deleteMultipleTasks(tasksAfterExpire); }
Example #5
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 #6
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testCountdownMillis() { String tag = "testCountdownMillis_" + getTimeStampRandom(); queue.add(withMethod(PULL).countdownMillis(10000).tag(tag)); sync(5000); // Give tasks a chance to become available. List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag.getBytes()).leasePeriod(1, TimeUnit.SECONDS).countLimit(1)); assertEquals(0, tasks.size()); sync(10000); tasks = queue.leaseTasks(LeaseOptions.Builder.withTag(tag).leasePeriod(1, TimeUnit.SECONDS).countLimit(1)); assertEquals(1, tasks.size()); queue.deleteTask(tasks); }
Example #7
Source File: NordnUploadAction.java From nomulus with Apache License 2.0 | 6 votes |
/** Leases and returns all tasks from the queue with the specified tag tld, in batches. */ List<TaskHandle> loadAllTasks(Queue queue, String tld) { ImmutableList.Builder<TaskHandle> allTasks = new ImmutableList.Builder<>(); while (true) { List<TaskHandle> tasks = retrier.callWithRetry( () -> queue.leaseTasks( LeaseOptions.Builder.withTag(tld) .leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS) .countLimit(TaskQueueUtils.getBatchSize())), TransientFailureException.class, DeadlineExceededException.class); if (tasks.isEmpty()) { return allTasks.build(); } allTasks.addAll(tasks); } }
Example #8
Source File: PullQueueAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testLeaseTasksByTagBytes() { String groupTag = "testLeaseTasksByTagBytes"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); taskTags.add(taskBaseName); byte[] tagBytes = taskBaseName.getBytes(); TaskOptions options = TaskOptions.Builder .withMethod(TaskOptions.Method.PULL) .taskName(taskBaseName + "_0") .tag(tagBytes) .payload(""); waitOnFuture(queue.addAsync(options)); sleep(5000); // Give tasks a chance to become available. List<TaskHandle> tasks = waitOnFuture(queue.leaseTasksByTagBytesAsync(1, TimeUnit.SECONDS, 10, tagBytes)); assertEquals(1, tasks.size()); do { queue.purge(); sleep(2000); tasks = waitOnFuture(queue.leaseTasksByTagBytesAsync(1, TimeUnit.SECONDS, 10, tagBytes)); } while (!tasks.isEmpty()); }
Example #9
Source File: NordnUploadAction.java From nomulus with Apache License 2.0 | 6 votes |
private void processLordnTasks() throws IOException { checkArgument(phase.equals(PARAM_LORDN_PHASE_SUNRISE) || phase.equals(PARAM_LORDN_PHASE_CLAIMS), "Invalid phase specified to Nordn servlet: %s.", phase); DateTime now = clock.nowUtc(); Queue queue = getQueue( phase.equals(PARAM_LORDN_PHASE_SUNRISE) ? LordnTaskUtils.QUEUE_SUNRISE : LordnTaskUtils.QUEUE_CLAIMS); String columns = phase.equals(PARAM_LORDN_PHASE_SUNRISE) ? COLUMNS_SUNRISE : COLUMNS_CLAIMS; List<TaskHandle> tasks = loadAllTasks(queue, tld); if (!tasks.isEmpty()) { String csvData = convertTasksToCsv(tasks, now, columns); uploadCsvToLordn(String.format("/LORDN/%s/%s", tld, phase), csvData); taskQueueUtils.deleteTasks(queue, tasks); } }
Example #10
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
/** * @param count Number of tasks to create. * @param taskBaseName add count to this name to create task name. * @param groupTag will be used during tearDown to delete tasks. * @param payload to be used by task. * @return List of TaskHandles from queue.add() */ private List<TaskHandle> addTasks(int count, String taskBaseName, String groupTag, String payload) { ArrayList<TaskOptions> optionList = new ArrayList<>(); for (int i = 0; i < count; i++) { TaskOptions options = withMethod(TaskOptions.Method.PULL) .taskName(taskBaseName + "_" + i) .tag(groupTag) .payload(payload); optionList.add(options); } taskTags.add(groupTag); List<TaskHandle> taskHandles = queue.add(optionList); sync(5000); // Give tasks a chance to become available. return taskHandles; }
Example #11
Source File: RefreshDnsOnHostRenameAction.java From nomulus with Apache License 2.0 | 6 votes |
/** Deletes a list of tasks from the given queue using a retrier. */ private static void deleteTasksWithRetry( final List<DnsRefreshRequest> refreshRequests, final Queue queue, AsyncTaskMetrics asyncTaskMetrics, Retrier retrier, OperationResult result) { if (refreshRequests.isEmpty()) { return; } final List<TaskHandle> tasks = refreshRequests.stream().map(DnsRefreshRequest::task).collect(toImmutableList()); retrier.callWithRetry(() -> queue.deleteTask(tasks), TransientFailureException.class); refreshRequests.forEach( r -> asyncTaskMetrics.recordAsyncFlowResult(DNS_REFRESH, result, r.requestedTime())); }
Example #12
Source File: AsyncTasksTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testTaskHandleContainsAllNecessaryProperties() throws Exception { String name = "testTaskHandleContainsAllNecessaryProperties-" + System.currentTimeMillis(); Queue queue = QueueFactory.getDefaultQueue(); TaskOptions options = withTaskName(name).payload("payload"); options.etaMillis(0); // TODO -- remove this once NPE is fixewd TaskHandle handle = waitOnFuture(queue.addAsync(options)); assertEquals("default", handle.getQueueName()); assertEquals(name, handle.getName()); assertEquals("payload", new String(handle.getPayload(), "UTF-8")); assertNotNull(handle.getEtaMillis()); assertEquals(0, (int) handle.getRetryCount()); }
Example #13
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testPullMultipleWithDiffTag() throws Exception { String groupTag = "testPullMultipleWithDiffTag"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); TaskHandle th1 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar")); TaskHandle th2 = queue.add(withMethod(PULL).tag(taskBaseName + "other").payload("foofoo".getBytes())); TaskHandle th3 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foofoo".getBytes())); sync(); try { List<TaskHandle> handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, taskBaseName); assertEquals(2, handles.size()); handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, taskBaseName + "other"); assertEquals(1, handles.size()); assertEquals(th2.getName(), handles.get(0).getName()); } finally { queue.deleteTask(th1); queue.deleteTask(th2); queue.deleteTask(th3); } }
Example #14
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testLeaseTasksByTagBytes() { String groupTag = "testLeaseTasksByTagBytes"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); taskTags.add(taskBaseName); byte[] tagBytes = taskBaseName.getBytes(); TaskOptions options = withMethod(TaskOptions.Method.PULL) .taskName(taskBaseName + "_0") .tag(tagBytes) .payload(""); queue.add(options); sync(5000); // Give tasks a chance to become available. List<TaskHandle> tasks = queue.leaseTasksByTagBytes(1, TimeUnit.SECONDS, 10, tagBytes); assertEquals(1, tasks.size()); queue.deleteTask(tasks); }
Example #15
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 #16
Source File: AppEngineTaskQueueTest.java From appengine-pipelines with Apache License 2.0 | 6 votes |
public void testEnqueueBatchTasks() { AppEngineTaskQueue queue = new AppEngineTaskQueue(); List<Task> tasks = new ArrayList<>(AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE); for (int i = 0; i < AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE; i++) { Task task = createTask(); tasks.add(task); } List<TaskHandle> handles = queue.addToQueue(tasks); assertEquals(AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE, handles.size()); for (int i = 0; i < AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE; i++) { assertEquals(tasks.get(i).getName(), handles.get(i).getName()); } handles = queue.addToQueue(tasks); assertEquals(0, handles.size()); }
Example #17
Source File: AppEngineTaskQueueTest.java From appengine-pipelines with Apache License 2.0 | 6 votes |
public void testEnqueueBatchTwoStages() { AppEngineTaskQueue queue = new AppEngineTaskQueue(); int batchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE * 2; List<Task> tasks = new ArrayList<>(batchSize); for (int i = 0; i < batchSize; i++) { Task task = createTask(); tasks.add(task); } int firstBatchSize = AppEngineTaskQueue.MAX_TASKS_PER_ENQUEUE; List<TaskHandle> handles = queue.addToQueue(tasks.subList(0, firstBatchSize)); assertEquals(firstBatchSize, handles.size()); for (int i = 0; i < firstBatchSize; i++) { assertEquals(tasks.get(i).getName(), handles.get(i).getName()); } handles = queue.addToQueue(tasks); // Duplicate is rejected (not counted) per batch. int expected = tasks.size() - firstBatchSize; assertEquals(expected, handles.size()); for (int i = 0; i < expected; i++) { assertEquals(tasks.get(firstBatchSize + i).getName(), handles.get(i).getName()); } }
Example #18
Source File: TaskQueueServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
private static void deferredTask(HttpServletRequest req, HttpServletResponse resp) throws IOException { String queue = req.getParameter("queue"); Queue q; if (queue == null) { q = QueueFactory.getDefaultQueue(); } else { q = QueueFactory.getQueue(queue); } final String data = req.getParameter("deferredData"); TaskOptions opts = TaskOptions.Builder.withPayload( new DeferredTask() { @Override public void run() { gotCalledBack(data); } }); latch = new CountDownLatch(1); TaskHandle handle = q.add(opts); resp.getWriter().print(handle.getQueueName()); }
Example #19
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 #20
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 #21
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 #22
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testBasicLease() { String taskGroupTag = "testBasicLease"; String taskBaseName = taskGroupTag + "_" + getTimeStampRandom(); int count = 10; addTasks(count, taskBaseName, taskGroupTag, payload); // lease 1 task from pull queue List<TaskHandle> handleList = leaseTasksByTag60Secs(taskGroupTag, 1, false); assertEquals(1, handleList.size()); deleteTaskByName(handleList.get(0).getName()); // lease the rest from pull queue handleList = leaseTasksByTag60Secs(taskGroupTag, MAX_LEASE_COUNT, false); assertEquals(count - 1, handleList.size()); for (TaskHandle t : handleList) { assertTrue(t.getName().startsWith(taskBaseName)); assertEquals(E2E_TESTING_PULL, t.getQueueName()); assertEquals(payload, new String(t.getPayload())); deleteTaskByName(t.getName()); } }
Example #23
Source File: PullQueueAsyncTest.java From appengine-tck with Apache License 2.0 | 6 votes |
/** * @param count Number of tasks to create. * @param taskBaseName add count to this name to create task name. * @param groupTag will be used during tearDown to delete tasks. * @param payload to be used by task. * @return List of TaskHandles from queue.add() */ private List<TaskHandle> addTasks(int count, String taskBaseName, String groupTag, String payload) { ArrayList<TaskOptions> optionList = new ArrayList<TaskOptions>(); for (int i = 0; i < count; i++) { TaskOptions options = TaskOptions.Builder .withMethod(TaskOptions.Method.PULL) .taskName(taskBaseName + "_" + i) .tag(groupTag) .payload(payload); optionList.add(options); } taskTags.add(groupTag); List<TaskHandle> taskHandles = waitOnFuture(queue.addAsync(optionList)); sleep(5000); // Give tasks a chance to become available. return taskHandles; }
Example #24
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testLeaseExpiration() { String groupTag = "testLeaseExpiration"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); deleteOnTearDownTags.add(taskBaseName); int count = 1; List<TaskHandle> taskList = addTasks(count, taskBaseName, groupTag, "nada"); long leaseDuration = 1000; LeaseOptions options = LeaseOptions.Builder .withTag(groupTag) .countLimit(count) .leasePeriod(leaseDuration, TimeUnit.MILLISECONDS); List<TaskHandle> tasks = queue.leaseTasks(options); assertEquals(count, tasks.size()); sync(leaseDuration + 1000); // wait for lease to expire List<TaskHandle> tasksAfterExpire = queue.leaseTasks(options); // expired, so it should be available for lease. assertEquals(count, tasksAfterExpire.size()); deleteMultipleTasks(tasksAfterExpire); }
Example #25
Source File: TasksTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testTaskHandleContainsAllNecessaryProperties() throws Exception { String name = "testTaskHandleContainsAllNecessaryProperties-" + System.currentTimeMillis(); Queue queue = QueueFactory.getDefaultQueue(); TaskOptions options = withTaskName(name).payload("payload"); options.etaMillis(0); // TODO -- remove this once NPE is fixewd TaskHandle handle = queue.add(options); assertEquals("default", handle.getQueueName()); assertEquals(name, handle.getName()); assertEquals("payload", new String(handle.getPayload(), "UTF-8")); assertNotNull(handle.getEtaMillis()); assertEquals(0, (int) handle.getRetryCount()); }
Example #26
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testPullMultipleWithSameTag() throws Exception { String groupTag = "testLeaseTasksByTagBytes"; String taskBaseName = groupTag + "_" + getTimeStampRandom(); TaskHandle th1 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar", "UTF-8")); TaskHandle th2 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foofoo".getBytes(), "UTF-8")); sync(); try { int numTasksToLease = 100; List<TaskHandle> handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, numTasksToLease, taskBaseName); assertEquals(2, handles.size()); Set<String> createdHandles = new HashSet<>(); createdHandles.add(th1.getName()); createdHandles.add(th2.getName()); Set<String> returnedHandles = new HashSet<>(); returnedHandles.add(handles.get(0).getName()); returnedHandles.add(handles.get(1).getName()); assertEquals(createdHandles, returnedHandles); } finally { queue.deleteTask(th1); queue.deleteTask(th2); } }
Example #27
Source File: Worker.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
/** * Process a batch of tasks from the queue. * @result true if tasks were processed. False if no tasks were leased. */ protected boolean processBatchOfTasks() { List<TaskHandle> tasks = leaseTasks(); if (tasks == null || tasks.size() == 0) { return false; } processLeasedTasks(tasks); return true; }
Example #28
Source File: Worker.java From io2014-codelabs with Apache License 2.0 | 5 votes |
/** * Check for already processed tasks. * * @param tasks the list of the tasks to be checked. * @return the set of task names that have already been processed. */ private Set<String> getAlreadyProcessedTaskNames(List<TaskHandle> tasks) { /* * To optimize for performance check in memcache first. A value from memcache may have been * evicted. Datastore is the authoritative source, so for any task not found in memcache check * in Datastore. */ List<String> taskNames = new ArrayList<String>(); for (TaskHandle task : tasks) { taskNames.add(task.getName()); } Map<String, Object> alreadyProcessedTaskNames = cache.getAll(taskNames); List<Key> keys = new ArrayList<Key>(); for (String taskName : taskNames) { if (!alreadyProcessedTaskNames.containsKey(taskName)) { keys.add(KeyFactory.createKey(PROCESSED_NOTIFICATION_TASKS_ENTITY_KIND, taskName)); } } if (keys.size() > 0) { Map<Key, Entity> entityMap = dataStore.get(keys); for (Key key : entityMap.keySet()) { alreadyProcessedTaskNames.put(key.getName(), 1); } } return alreadyProcessedTaskNames.keySet(); }
Example #29
Source File: Worker.java From io2014-codelabs with Apache License 2.0 | 5 votes |
/** * Process a batch of tasks from the queue. * @result true if tasks were processed. False if no tasks were leased. */ protected boolean processBatchOfTasks() { List<TaskHandle> tasks = leaseTasks(); if (tasks == null || tasks.size() == 0) { return false; } processLeasedTasks(tasks); return true; }
Example #30
Source File: PullQueueTest.java From appengine-tck with Apache License 2.0 | 5 votes |
/** * Try to make leasing tasks less flaky by doing retries. * * @param groupTag group tag to filter by * @param count number of tasks to lease. * @param zeroSizeAcceptable when an empty list is okay or expected. * @return List<TaskHandle> */ private List<TaskHandle> leaseTasksByTag60Secs(String groupTag, int count, boolean zeroSizeAcceptable) { LeaseOptions options = LeaseOptions.Builder .withTag(groupTag) .countLimit(count) // Max lease count is 1000. .leasePeriod(60, TimeUnit.SECONDS); return leaseTasksByOptions(groupTag, count, zeroSizeAcceptable, options); }