Package com.google.appengine.api.taskqueue

Examples of com.google.appengine.api.taskqueue.TaskHandle


        }
       
        URL uri = new URL(url);
        String path = uri.getPath();   
        Queue queue = QueueFactory.getDefaultQueue();
        TaskHandle task = queue.add(withUrl(path)
            .payload(request.toString())
            .countdownMillis(delay));
       
        // store task information
        DateTime timestamp = DateTime.now().plus(delay);
        GaeTask storedTask = new GaeTask(task.getName(),
            agentId, timestamp.toString());
        ObjectDatastore datastore = new AnnotationObjectDatastore();
        datastore.store(storedTask);
       
        return task.getName();     
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }

      // TODO: throw error?
View Full Code Here


        TaskOptions options = TaskUtils.newTaskOptions(ChunkedRuleProcessor.class)
            .param(pCHUNK_ID, Integer.toString(chunkId))
            .param(pSTART_ID, KeyFactory.keyToString(startKey))
            .param(pLAST_ID, KeyFactory.keyToString(lastKey))
            .param(pCHUNK_SIZE, Long.toString(chunkSize));
        TaskHandle handle = queue.add(options);
        Logger.info("Enq'd new task. Task id: %s Start key: %s Last key: %s",
                handle.getName(), startKey, lastKey);
        return handle;
    }
View Full Code Here

        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());
    }
View Full Code Here

    }

    @Test
    public void testTaskHandleContainsAutoGeneratedTaskNameWhenTaskNameNotDefinedInTaskOptions() throws Exception {
        Queue queue = QueueFactory.getDefaultQueue();
        TaskHandle handle = queue.add();
        assertNotNull(handle.getName());
    }
View Full Code Here

    }

    @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);
        }
    }
View Full Code Here

    }

    @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);
        }
    }
View Full Code Here

    }

    @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());
View Full Code Here

    @Test
    public void testPullWithTag() throws Exception {
        String groupTag = "testPullWithTag";
        String taskBaseName = groupTag + "_" + getTimeStampRandom();

        TaskHandle th = queue.add(withMethod(PULL).tag(taskBaseName));
        try {
            List<TaskHandle> handles = queue.leaseTasksByTag(30, TimeUnit.MINUTES, 100, taskBaseName);
            assertFalse(handles.isEmpty());
            TaskHandle lh = handles.get(0);
            assertEquals(th.getName(), lh.getName());
        } finally {
            queue.deleteTask(th);
        }
    }
View Full Code Here

    @Test
    public void testPullWithGroupByTag() throws Exception {
        String groupTag = "testPullWithGroupTag";
        String taskBaseName = groupTag + "_" + getTimeStampRandom();
        TaskHandle th1 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar", "UTF-8"));
        TaskHandle th2 = queue.add(withMethod(PULL).tag(taskBaseName + "other").payload("foofoo", "UTF-8"));
        TaskHandle th3 = queue.add(withMethod(PULL).tag(taskBaseName).payload("foofoo".getBytes(), "UTF-8"));

        sync(5000); // Give some time for the tasks to be available for lease.

        try {
            // If options specifies no tag, but does specify groupByTag,
            // only tasks having the same tag as the task with earliest eta will be returned.
            LeaseOptions options = LeaseOptions.Builder.withLeasePeriod(30, TimeUnit.SECONDS).countLimit(100).groupByTag();
            List<TaskHandle> handles = queue.leaseTasks(options);

            // The first and third tasks with the same tag should be returned.
            assertEquals(2, handles.size());

            Set<String> createdHandles = new HashSet<>();
            createdHandles.add(th1.getName());
            createdHandles.add(th3.getName());

            Set<String> returnedHandles = new HashSet<>();
            returnedHandles.add(handles.get(0).getName());
            returnedHandles.add(handles.get(1).getName());
View Full Code Here

        String groupTag = "testExtractParams";
        String taskBaseName = groupTag + "_" + getTimeStampRandom();
        queue.add(withMethod(PULL).tag(taskBaseName).payload("foobar=baz", "UTF-8"));
        List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder.withCountLimit(1).leasePeriod(1, TimeUnit.MINUTES));
        Assert.assertEquals(1, tasks.size());
        TaskHandle th = tasks.get(0);
        List<Map.Entry<String, String>> entries = th.extractParams();
        Assert.assertEquals(1, entries.size());
        Assert.assertEquals("foobar", entries.get(0).getKey());
        Assert.assertEquals("baz", entries.get(0).getValue());
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.taskqueue.TaskHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.