Class CloudTasksUtils
- All Implemented Interfaces:
Serializable
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
ConstructorDescriptionCloudTasksUtils
(Retrier retrier, Clock clock, String projectId, String locationId, String oauthClientId, GoogleCredentialsBundle credential, CloudTasksUtils.SerializableCloudTasksClient client) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.cloud.tasks.v2.Task
createTask
(Class<? extends Runnable> actionClazz, Action.Method method, com.google.common.collect.Multimap<String, String> params) Create aTask
to be enqueued.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 aTask
to be enqueued.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 aTask
to be enqueued with delay ofduration
.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 aTask
to be enqueued with a random delay up tojitterSeconds
.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 aTask
to be enqueued with a random delay up tojitterSeconds
.com.google.cloud.tasks.v2.Task
com.google.common.collect.ImmutableList
<com.google.cloud.tasks.v2.Task> com.google.common.collect.ImmutableList
<com.google.cloud.tasks.v2.Task>
-
Constructor Details
-
CloudTasksUtils
@Inject public CloudTasksUtils(Retrier retrier, Clock clock, @Config("projectId") String projectId, @Config("locationId") String locationId, @Config("oauthClientId") String oauthClientId, @ApplicationDefaultCredential GoogleCredentialsBundle credential, CloudTasksUtils.SerializableCloudTasksClient client)
-
-
Method Details
-
enqueue
-
enqueue
-
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 aTask
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 aTask
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 withAction
.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 aTask
to be enqueued with a random delay up tojitterSeconds
.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 aTask
to be enqueued with a random delay up tojitterSeconds
.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 withAction
.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 aTask
to be enqueued with delay ofduration
.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 withAction
.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:
-