本文整理匯總了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;
}
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}