When creating a task, you can specify the maximum number of times to retry a
failed task, set a time limit for retry attempts, and control the interval
between attempts by using the
projects.locations.queues.tasks.create
method. Once a task is successfully executed, it is removed from the queue. In
all cases, the maximum task retention limit also
applies.
This task-level retry configuration overrides the queue-level retry configuration for the task.
Configure retries when creating a task
The following example demonstrates setting retry parameters when creating an
HTTP target task by sending a direct request to the Cloud Tasks API. You can
use the same retry parameters when
creating an App Engine task. For
more parameter details, see the
RetryConfig settings for the
Task resource.
Before using any of the request data, make the following replacements:
PROJECT_ID: required. The project ID of the Google Cloud project where the task will be created.REGION: required. The region in which the queue is deployed—for example,us-central1.QUEUE_ID: required. The ID of the queue to which the task will be added.URL: required. The fully qualified URL that the request will be sent to. This string must begin with eitherhttp://orhttps://—for example:https://www.example.com.SERVICE_ACCOUNT_EMAIL: optional. The service account email used to generate an authorization token that is included in the request sent to the target when executing the task. The service account must be in the same project as the queue. The caller must have theiam.serviceAccounts.actAspermission for the service account.To generate an OAuth2 access token instead of an OpenID Connect token, replace the
oidcTokenfield withoauthTokento specify the service account email.MAX_ATTEMPTS: optional. The maximum number of attempts for a task, including the first. To allow unlimited retries, set this to-1.MAX_RETRY_DURATIONstill applies even ifMAX_ATTEMPTSis reached or set to-1.MAX_RETRY_DURATION: optional. The maximum amount of time for retrying a failed task, measured from when the task was first attempted. The value must be a string that ends in "s," such as5s. To specify an unlimited duration, set this to0s.MAX_ATTEMPTSstill applies even ifMAX_RETRY_DURATIONis reached or set to0s.MIN_INTERVAL: optional. The minimum amount of time to wait between retry attempts. The value must be a string that ends in "s," such as5s.MAX_INTERVAL: optional. The maximum amount of time to wait between retry attempts. The value must be a string that ends in "s," such as5s.MAX_DOUBLINGS: optional. The maximum number of times that the interval between failed task retries will be doubled before the increase becomes constant. A task's retry interval starts atMIN_INTERVAL, then doublesMAX_DOUBLINGStimes, then increases linearly, and finally retries at intervals ofMAX_INTERVALup toMAX_ATTEMPTStimes.For example, if
MIN_INTERVALis10s,MAX_INTERVALis300s, andMAX_DOUBLINGSis3, the retry interval will double3times, increase linearly by 2^3 * 10s, and then retry at intervals ofMAX_INTERVALuntil the task has been attemptedMAX_ATTEMPTStimes: 10s, 20s, 40s, 80s, 160s, 240s, 300s, 300s, and so forth.SCHEDULE_TIME: optional. The time when the task is scheduled to be attempted, in RFC 3339 format—for example,2026-10-02T15:01:23Z. If the time isn't set or is in the past, Cloud Tasks will set it to the current time.
Request JSON body:
{
"task": {
"httpRequest": {
"url": "URL",
"httpMethod": "POST",
"oidcToken": {
"serviceAccountEmail": "SERVICE_ACCOUNT_EMAIL"
}
},
"retryConfig": {
"maxAttempts": MAX_ATTEMPTS,
"maxRetryDuration": "MAX_RETRY_DURATION",
"minBackoff": "MIN_INTERVAL",
"maxBackoff": "MAX_INTERVAL",
"maxDoublings": MAX_DOUBLINGS
},
"scheduleTime": "SCHEDULE_TIME"
}
}
To send your request, expand one of these options:
If successful, the response body contains the newly created instance of
the Task resource.
{
"name": "projects/PROJECT_ID/locations/REGION/queues/QUEUE_ID/tasks/TASK_ID",
"httpRequest": {
"url": "URL",
"httpMethod": "POST",
"headers": {
"User-Agent": "Google-Cloud-Tasks"
},
"oidcToken": {
"serviceAccountEmail": "SERVICE_ACCOUNT_EMAIL",
"audience": "URL"
}
},
"retryConfig": {
"maxAttempts": MAX_ATTEMPTS,
"maxRetryDuration": "MAX_RETRY_DURATION",
"minBackoff": "MIN_INTERVAL",
"maxBackoff": "MAX_INTERVAL",
"maxDoublings": MAX_DOUBLINGS
},
"scheduleTime": "SCHEDULE_TIME",
"createTime": "2026-04-30T19:11:50Z",
"dispatchDeadline": "600s",
"view": "BASIC"
}