當前位置: 首頁>>代碼示例>>Java>>正文


Java Queue.leaseTasks方法代碼示例

本文整理匯總了Java中com.google.appengine.api.taskqueue.Queue.leaseTasks方法的典型用法代碼示例。如果您正苦於以下問題:Java Queue.leaseTasks方法的具體用法?Java Queue.leaseTasks怎麽用?Java Queue.leaseTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.taskqueue.Queue的用法示例。


在下文中一共展示了Queue.leaseTasks方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadAllTasks

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
/** Leases and returns all tasks from the queue with the specified tag tld, in batches. */
public static List<TaskHandle> loadAllTasks(Queue queue, String tld) {
  ImmutableList.Builder<TaskHandle> allTasks = new ImmutableList.Builder<>();
  int numErrors = 0;
  long backOff = backOffMillis;
  while (true) {
    try {
      List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
          .withTag(tld)
          .leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
          .countLimit(BATCH_SIZE));
      allTasks.addAll(tasks);
      if (tasks.isEmpty()) {
        return allTasks.build();
      }
    } catch (TransientFailureException | DeadlineExceededException e) {
      if (++numErrors >= 3) {
        throw new RuntimeException("Error leasing tasks", e);
      }
      Uninterruptibles.sleepUninterruptibly(backOff, TimeUnit.MILLISECONDS);
      backOff *= 2;
    }
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:25,代碼來源:LordnTask.java

示例2: leaseAndDeleteTasks

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
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());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:18,代碼來源:TaskQueueServlet.java

示例3: testBasics

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:17,代碼來源:SmokeTest.java

示例4: testPullParams

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:15,代碼來源:PullTest.java

示例5: testPullPayload

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:15,代碼來源:PullTest.java

示例6: testLeaseTasksOnlyReturnsSpecifiedNumberOfTasks

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:16,代碼來源:PullTest.java

示例7: testLeaseFromNonPullQueue

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test(expected = InvalidQueueModeException.class)
public void testLeaseFromNonPullQueue() {
    Queue remoteQueue = QueueFactory.getQueue(E2E_TESTING_REMOTE);
    remoteQueue.leaseTasks(1, TimeUnit.MILLISECONDS, 1);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:6,代碼來源:PullQueueTest.java

示例8: testLeaseNonExistQueue

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test(expected = IllegalStateException.class)
public void testLeaseNonExistQueue() {
    Queue nonExistQueue = QueueFactory.getQueue("nonExistQueue");
    nonExistQueue.leaseTasks(1, TimeUnit.MILLISECONDS, 1);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:6,代碼來源:PullQueueTest.java

示例9: testLeaseTaskFromPushQueueThrowsException

import com.google.appengine.api.taskqueue.Queue; //導入方法依賴的package包/類
@Test(expected = InvalidQueueModeException.class)
public void testLeaseTaskFromPushQueueThrowsException() {
    Queue pushQueue = QueueFactory.getDefaultQueue();
    pushQueue.leaseTasks(1000, TimeUnit.SECONDS, 1);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:6,代碼來源:TasksTest.java


注:本文中的com.google.appengine.api.taskqueue.Queue.leaseTasks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。