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

The following examples show how to use com.google.appengine.api.taskqueue.TaskOptions#param() . 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: TaskQueuesLogic.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds the given task, to be run after the specified time, to the specified queue.
 *
 * @param task the task object containing the details of task to be added
 * @param countdownTime the time delay for the task to be executed
 */
public void addDeferredTask(TaskWrapper task, long countdownTime) {
    Queue requiredQueue = QueueFactory.getQueue(task.getQueueName());
    TaskOptions taskToBeAdded = TaskOptions.Builder.withUrl(task.getWorkerUrl());
    if (countdownTime > 0) {
        taskToBeAdded.countdownMillis(countdownTime);
    }

    for (Map.Entry<String, String[]> entry : task.getParamMap().entrySet()) {
        String name = entry.getKey();
        String[] values = entry.getValue();

        for (String value : values) {
            taskToBeAdded = taskToBeAdded.param(name, value);
        }
    }

    requiredQueue.add(taskToBeAdded);
}
 
Example 2
Source File: AsyncTaskEnqueuer.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/**
 * Enqueues a task to asynchronously re-save an entity at some point(s) in the future.
 *
 * <p>Multiple re-save times are chained one after the other, i.e. any given run will re-enqueue
 * itself to run at the next time if there are remaining re-saves scheduled.
 */
public void enqueueAsyncResave(
    ImmutableObject entityToResave, DateTime now, ImmutableSortedSet<DateTime> whenToResave) {
  DateTime firstResave = whenToResave.first();
  checkArgument(isBeforeOrAt(now, firstResave), "Can't enqueue a resave to run in the past");
  Key<ImmutableObject> entityKey = Key.create(entityToResave);
  Duration etaDuration = new Duration(now, firstResave);
  if (etaDuration.isLongerThan(MAX_ASYNC_ETA)) {
    logger.atInfo().log(
        "Ignoring async re-save of %s; %s is past the ETA threshold of %s.",
        entityKey, firstResave, MAX_ASYNC_ETA);
    return;
  }
  logger.atInfo().log("Enqueuing async re-save of %s to run at %s.", entityKey, whenToResave);
  String backendHostname = appEngineServiceUtils.getServiceHostname("backend");
  TaskOptions task =
      TaskOptions.Builder.withUrl(PATH_RESAVE_ENTITY)
          .method(Method.POST)
          .header("Host", backendHostname)
          .countdownMillis(etaDuration.getMillis())
          .param(PARAM_RESOURCE_KEY, entityKey.getString())
          .param(PARAM_REQUESTED_TIME, now.toString());
  if (whenToResave.size() > 1) {
    task.param(PARAM_RESAVE_TIMES, Joiner.on(',').join(whenToResave.tailSet(firstResave, false)));
  }
  addTaskToQueueWithRetry(asyncActionsPushQueue, task);
}
 
Example 3
Source File: ReadDnsQueueActionTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private static TaskOptions createRefreshTask(String name, TargetType type) {
  TaskOptions options =
      TaskOptions.Builder.withMethod(Method.PULL)
          .param(DNS_TARGET_TYPE_PARAM, type.toString())
          .param(DNS_TARGET_NAME_PARAM, name)
          .param(DNS_TARGET_CREATE_TIME_PARAM, "3000-01-01TZ");
  String tld = InternetDomainName.from(name).parts().reverse().get(0);
  return options.param("tld", tld);
}
 
Example 4
Source File: TaskServlet.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a custom task in the custom queue.
 * @param paramMap map of parameters to store
 */
public static void register_customTask( final java.util.Map< String, String > paramMap ) {
	final TaskOptions taskOptions = buildTask( OPERATION_CUSTOM );
	
	for ( final Entry< String, String > paramEntry : paramMap.entrySet() )
		taskOptions.param( paramEntry.getKey(), paramEntry.getValue() );
	
	QueueFactory.getQueue( QUEUE_NAME_CUSTOM ).add( taskOptions );
}
 
Example 5
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 6
Source File: AppEngineTaskQueue.java    From appengine-pipelines with Apache License 2.0 4 votes vote down vote up
private static void addProperties(TaskOptions taskOptions, Properties properties) {
  for (String paramName : properties.stringPropertyNames()) {
    String paramValue = properties.getProperty(paramName);
    taskOptions.param(paramName, paramValue);
  }
}
 
Example 7
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());
}