Class CloudTasksUtils

java.lang.Object
google.registry.batch.CloudTasksUtils
All Implemented Interfaces:
Serializable

public class CloudTasksUtils extends Object implements Serializable
Utilities for dealing with Cloud Tasks.
See Also:
  • Constructor Details

  • Method Details

    • enqueue

      public com.google.cloud.tasks.v2.Task enqueue(String queue, com.google.cloud.tasks.v2.Task task)
    • enqueue

      public com.google.common.collect.ImmutableList<com.google.cloud.tasks.v2.Task> enqueue(String queue, Iterable<com.google.cloud.tasks.v2.Task> tasks)
    • enqueue

      public com.google.common.collect.ImmutableList<com.google.cloud.tasks.v2.Task> enqueue(String queue, com.google.cloud.tasks.v2.Task... tasks)
    • createTask

      protected com.google.cloud.tasks.v2.Task createTask(String path, Action.Method method, Action.Service service, com.google.common.collect.Multimap<String,String> params)
      Create a Task to be enqueued.

      This uses the standard Cloud Tasks auth format to create and send an OIDC ID token with the default service account as the principal. That account must have permission to submit tasks to Cloud Tasks.

      The caller of this method is responsible for passing in the appropriate service based on the runtime (GAE/GKE). Use the overload that takes an action class if possible.

      Parameters:
      path - the relative URI (staring with a slash and ending without one).
      method - the HTTP method to be used for the request.
      service - the GAE/GKE service to route the request to.
      params - a multimap of URL query parameters. Duplicate keys are saved as is, and it is up to the server to process the duplicate keys.
      Returns:
      the enqueued task.
      See Also:
    • createTask

      public com.google.cloud.tasks.v2.Task createTask(Class<? extends Runnable> actionClazz, Action.Method method, com.google.common.collect.Multimap<String,String> params)
      Create a Task to be enqueued.

      This uses the standard Cloud Tasks auth format to create and send an OIDC ID token with the default service account as the principal. That account must have permission to submit tasks to Cloud Tasks.

      Prefer this overload over the one where the path and service are explicit defined, as this class will automatically determine the service to use based on the action and the runtime.

      Parameters:
      actionClazz - the action class to run, must be annotated with Action.
      method - the HTTP method to be used for the request.
      params - a multimap of URL query parameters. Duplicate keys are saved as is, and it is up to the server to process the duplicate keys.
      Returns:
      the enqueued task.
      See Also:
    • createTaskWithJitter

      public com.google.cloud.tasks.v2.Task createTaskWithJitter(String path, Action.Method method, Action.Service service, com.google.common.collect.Multimap<String,String> params, Optional<Integer> jitterSeconds)
      Create a Task to be enqueued with a random delay up to jitterSeconds.

      The caller of this method is responsible for passing in the appropriate service based on the runtime (GAE/GKE). Use the overload that takes an action class if possible.

      Parameters:
      path - the relative URI (staring with a slash and ending without one).
      method - the HTTP method to be used for the request.
      service - the GAE/GKE service to route the request to.
      params - a multimap of URL query parameters. Duplicate keys are saved as is, and it is up to the server to process the duplicate keys.
      jitterSeconds - the number of seconds that a task is randomly delayed up to.
      Returns:
      the enqueued task.
      See Also:
    • createTaskWithJitter

      public com.google.cloud.tasks.v2.Task createTaskWithJitter(Class<? extends Runnable> actionClazz, Action.Method method, com.google.common.collect.Multimap<String,String> params, Optional<Integer> jitterSeconds)
      Create a Task to be enqueued with a random delay up to jitterSeconds.

      Prefer this overload over the one where the path and service are explicit defined, as this class will automatically determine the service to use based on the action and the runtime.

      Parameters:
      actionClazz - the action class to run, must be annotated with Action.
      method - the HTTP method to be used for the request.
      params - a multimap of URL query parameters. Duplicate keys are saved as is, and it is up to the server to process the duplicate keys.
      jitterSeconds - the number of seconds that a task is randomly delayed up to.
      Returns:
      the enqueued task.
      See Also:
    • createTaskWithDelay

      public com.google.cloud.tasks.v2.Task createTaskWithDelay(Class<? extends Runnable> actionClazz, Action.Method method, com.google.common.collect.Multimap<String,String> params, org.joda.time.Duration delay)
      Create a Task to be enqueued with delay of duration.

      Prefer this overload over the one where the path and service are explicit defined, as this class will automatically determine the service to use based on the action and the runtime.

      Parameters:
      actionClazz - the action class to run, must be annotated with Action.
      method - the HTTP method to be used for the request.
      params - a multimap of URL query parameters. Duplicate keys are saved as is, and it is up to the server to process the duplicate keys.
      delay - the amount of time that a task needs to delayed for.
      Returns:
      the enqueued task.
      See Also: