Java Code Examples for com.google.appengine.api.taskqueue.TaskOptions#etaMillis()

The following examples show how to use com.google.appengine.api.taskqueue.TaskOptions#etaMillis() . 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: AsyncTasksTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: TasksTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: GenerateEscrowDepositCommand.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {

  if (tlds.isEmpty()) {
    throw new ParameterException("At least one TLD must be specified");
  }
  assertTldsExist(tlds);

  for (DateTime watermark : watermarks) {
    if (!watermark.withTimeAtStartOfDay().equals(watermark)) {
      throw new ParameterException("Each watermark date must be the start of a day");
    }
  }

  if ((revision != null) && (revision < 0)) {
    throw new ParameterException("Revision must be greater than or equal to zero");
  }

  if (outdir.isEmpty()) {
    throw new ParameterException("Output subdirectory must not be empty");
  }

  // Unlike many tool commands, this command is actually invoking an action on the backend module
  // (because it's a mapreduce). So we invoke it in a different way.
  String hostname = appEngineServiceUtils.getCurrentVersionHostname("backend");
  TaskOptions opts =
      withUrl(RdeStagingAction.PATH)
          .header("Host", hostname)
          .param(PARAM_MANUAL, String.valueOf(true))
          .param(PARAM_MODE, mode.toString())
          .param(PARAM_DIRECTORY, outdir)
          .param(PARAM_TLDS, tlds.stream().collect(Collectors.joining(",")))
          .param(
              PARAM_WATERMARKS,
              watermarks.stream().map(DateTime::toString).collect(Collectors.joining(",")));
  if (revision != null) {
    opts = opts.param(PARAM_REVISION, String.valueOf(revision));
  }
  if (maybeEtaMillis.isPresent()) {
    opts = opts.etaMillis(maybeEtaMillis.get());
  }
  queue.add(opts);
}
 
Example 4
Source File: TaskQueueServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
private void addTask(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  String queue = req.getParameter("queue");
  Queue q;
  if (queue == null) {
    q = QueueFactory.getDefaultQueue();
  } else {
    q = QueueFactory.getQueue(queue);
  }
  TaskOptions.Method method = TaskOptions.Method.valueOf(req.getParameter("httpmethod"));
  String url = req.getParameter("taskUrl");
  if (url == null) {
    url = req.getServletPath();
  }
  TaskOptions opts =
      TaskOptions.Builder.withUrl(url).header("myheader", "blarg29").method(method);

  if (method == TaskOptions.Method.POST || method == TaskOptions.Method.PUT) {
    opts.payload("this=that");
  } else {
    opts.param("myparam", "yam28");
  }
  String execTimeMs = req.getParameter("execTimeMs");
  if (execTimeMs != null) {
    opts.etaMillis(Long.valueOf(execTimeMs));
  }
  String requestNamespace = req.getParameter("requestNamespace");
  if (requestNamespace != null) {
    /* We could override the current environment and set the request namespace
     * but that's a little overkill and already tested in
     * com.google.appengine.api.taskqueue.TaskQueueTest .
     */
    opts.header(DEFAULT_NAMESPACE_HEADER, requestNamespace);
  }
  String currentNamespace = req.getParameter("currentNamespace");
  if (currentNamespace != null) {
    /* We could also do this:
     * opts.header(CURRENT_NAMESPACE_HEADER, currentNamespace);
     */
    NamespaceManager.set(currentNamespace);
  }
  latch = new CountDownLatch(1);
  TaskHandle handle = q.add(opts);
  resp.getWriter().print(handle.getQueueName());
}