google.appengine.api.taskqueue.taskqueue module
Summary
Task Queue API.
Enables an application to queue background work for itself. Work is done through webhooks that process tasks pushed from a queue, or workers that manually pull tasks from a queue. In push queues, tasks will execute in best-effort order of ETA. Webhooks that fail will cause tasks to be retried at a later time. In pull queues, workers are responsible of leasing tasks for processing and deleting the tasks when completed. Multiple queues cab exist with independent throttling controls.
Webhook URLs can be specified directly for push tasks, or the default URL scheme can be used, which will translate task names into URLs relative to a queue’s base path. A default queue is also provided for simple usage.
Contents
- exception google.appengine.api.taskqueue.taskqueue.BadTaskStateErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The task is in the wrong state for the requested operation.
- google.appengine.api.taskqueue.taskqueue.BadTransactionState
-
alias of BadTransactionStateError
- exception google.appengine.api.taskqueue.taskqueue.BadTransactionStateErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The state of the current transaction does not permit this operation.
- exception google.appengine.api.taskqueue.taskqueue.DatastoreErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
There was a datastore error while accessing the queue.
- exception google.appengine.api.taskqueue.taskqueue.DuplicateTaskNameErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
Two tasks have the same name.
When adding multiple tasks to a queue in a batch, more than one task cannot have the same name.
- exception google.appengine.api.taskqueue.taskqueue.Errorsource
-
Bases: exceptions.Exception
Base class for exceptions in this module.
- exception google.appengine.api.taskqueue.taskqueue.InternalErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
An internal error occurred while accessing this queue.
If the problem continues, contact the App Engine team through the support forum. Be sure to include a description of your problem.
- exception google.appengine.api.taskqueue.taskqueue.InvalidQueueErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The queue’s configuration is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidQueueNameErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidQueueError
The name of the queue is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidTaskErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The parameters, headers, or method of the task is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidTaskNameErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The name of the task is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidUrlErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The relative URL used for the task is invalid.
- exception google.appengine.api.taskqueue.taskqueue.PermissionDeniedErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The requested operation is not allowed for this app.
- exception google.appengine.api.taskqueue.taskqueue.TaskAlreadyExistsErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The task already exists. It has not yet run.
- exception google.appengine.api.taskqueue.taskqueue.TaskTooLargeErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The task is too large with its headers and payload.
- exception google.appengine.api.taskqueue.taskqueue.TombstonedTaskErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The task has been tombstoned.
A task with the same name was previously executed in the queue; names should be unique within a queue.
- exception google.appengine.api.taskqueue.taskqueue.TooManyTasksErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
Too many tasks were present in a single function call.
- exception google.appengine.api.taskqueue.taskqueue.TransientErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
A transient error occurred while accessing the queue. Try again later.
- exception google.appengine.api.taskqueue.taskqueue.UnknownQueueErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The queue specified is unknown.
- exception google.appengine.api.taskqueue.taskqueue.InvalidLeaseTimeErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The lease time period is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidMaxTasksErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The requested maximum number of tasks in
lease_tasks
is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidDeadlineErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The requested deadline in
lease_tasks
is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidQueueModeErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
Invokes a pull queue operation on a push queue or vice versa.
- exception google.appengine.api.taskqueue.taskqueue.TransactionalRequestTooLargeErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.TaskTooLargeError
The total size of this transaction (including tasks) was too large.
- exception google.appengine.api.taskqueue.taskqueue.TaskLeaseExpiredErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The task lease could not be renewed because it had already expired.
- exception google.appengine.api.taskqueue.taskqueue.QueuePausedErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The queue is paused and cannot process modify task lease requests.
- exception google.appengine.api.taskqueue.taskqueue.InvalidEtaErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.InvalidTaskError
The task’s ETA is invalid.
- exception google.appengine.api.taskqueue.taskqueue.InvalidTagErrorsource
-
Bases: google.appengine.api.taskqueue.taskqueue.Error
The specified tag is invalid.
- class google.appengine.api.taskqueue.taskqueue.Queue(name='default')source
-
Bases: object
Represents a queue.
The
Queue
class is used to prepare tasks for offline execution by App Engine.A queue object is instantiated by name. The name must correspond either to the default queue (provided by the system) or a user-defined queue as specified in the application’s
queue.yaml
configuration file. The queue object can then be used to insert new task instances for offline execution by App Engine.Multiple queue objects can correspond to the same underlying system queue. However, a single task object can only be added to one queue.
- add(task, transactional=False)source
Adds a task or list of tasks into this queue.
If a list of more than one tasks is given, a raised exception does not guarantee that no tasks were added to the queue (unless
transactional
is set toTrue
). To determine which tasks were successfully added when an exception is raised, check theTask.was_enqueued
property.Push tasks, or those with a method not equal to pull cannot be added to queues in pull mode. Similarly, pull tasks cannot be added to queues in push mode.
If a
ParametersTaskAlreadyExistsError
orTombstonedTaskError
is raised, the caller can be guaranteed that for each one of the provided tasks, either the corresponding task was successfully added, or a task with the given name was successfully added in the past.-
task – A task instance or a list of task instances that will be added to the queue. If
task
is set to a list of task objects, all tasks are added to the queue. IfTransactional=True
, then all of the tasks are added in the same active Datastore transaction, and if any of the tasks cannot be added to the queue, none of the tasks are added to the queue, and the Datastore transaction will fail. Iftransactional=False
, a failure to add any task to the queue will raise an exception, but other tasks will be added to the queue. -
transactional – If
True
, transactional tasks will be added to the queue but cannot be run or leased until after the transaction succeeds. If the transaction fails then the tasks will be removed from the queue (and therefore will never run). IfFalse
, the added tasks are available to run immediately; any enclosing transaction’s success or failure is ignored.
The task or list of tasks that was supplied to this method. Successfully queued tasks will have a valid queue name and task name after the call; these task objects are marked as queued and cannot be added again.
Raises-
BadTaskStateError – If the task has already been added to a queue.
-
BadTransactionStateError – If the
transactional
argument isTrue
but this call is being made outside of the context of a transaction. -
DuplicateTaskNameError – If a task name is repeated in the request.
-
InvalidTaskNameError – If a task name is provided but is not valid.
-
InvalidTaskError – If both push and pull tasks exist in the task list.
-
InvalidQueueModeError – If a pull task is added to a queue in push mode, or if a push task is added to a queue in pull mode.
-
TaskAlreadyExistsError – If a task with the same name as a given name has previously been added to the queue.
-
TombstonedTaskError – If a task with the same name as a given name has previously been added to the queue and deleted.
-
TooManyTasksError – If a task contains more than
MAX_TASKS_PER_ADD
tasks. -
TransactionalRequestTooLargeError – If transactional is
True
and the total size of the tasks and supporting request data exceeds theMAX_TRANSACTIONAL_REQUEST_SIZE_BYTES
quota. -
Error-subclass on application errors.
-
- add_async(task, transactional=False, rpc=None)source
Asynchronously adds a task or list of tasks into this queue.
This function is identical to
Parametersadd()
except that it returns an asynchronous object. You can callget_result()
on the return value to block on the call.-
task – A task instance or a list of task instances that will be added to the queue. If
task
is a list of task objects, all tasks are added to the queue. IfTransactional=True
, then all of the tasks are added in the same active Datastore transaction, and if any of the tasks cannot be added to the queue, none of the tasks are added to the queue and the Datastore transaction will fail. Iftransactional=False
, a failure to add a task to the queue will raise an exception, but other tasks will be enqueued. -
transactional – If
True
, transactional tasks will be added to the queue but cannot be run or leased until after the transaction succeeds. If the transaction fails, the tasks will be removed from the queue (and therefore will never run). IfFalse
, the added tasks are available to run immediately; any enclosing transaction’s success or failure is ignored. -
rpc – An optional UserRPC object.
A UserRPC object. Call
Raisesget_result()
to complete the RPC and obtain the task or list of tasks that was supplied to this method. Successfully queued tasks will have a valid queue name and task name after the call; such task objects are marked as queued and cannot be added again.-
BadTaskStateError – If the tasks have already been added to a queue.
-
BadTransactionStateError – If the transactional argument is
True
but this call is being made outside of the context of a transaction. -
DuplicateTaskNameError – If a task name is repeated in the request.
-
InvalidTaskError – If both push and pull tasks exist in the task list.
-
InvalidTaskNameError – If a task name is provided but is not valid.
-
TooManyTasksError – If the task contains more than
MAX_TASKS_PER_ADD
tasks. -
TransactionalRequestTooLargeError – If transactional is
True
and the total size of the tasks and supporting request data exceeds theMAX_TRANSACTIONAL_REQUEST_SIZE_BYTES
quota.
-
- delete_tasks(task)source
Deletes a task or list of tasks in this queue.
When multiple tasks are specified, an exception will be raised if any individual task fails to be deleted. Check the
task.was_deleted
property.The task name is the only task attribute that is used to select tasks for deletion. If any task exists that is unnamed or with the
Parameterswas_deleted
property set toTrue
, aBadTaskStateError
will be raised immediately.task – A task instance or a list of task instances that will be deleted from the queue.
ReturnsThe task or list of tasks passed into this call.
Raises-
BadTaskStateError – If the tasks to be deleted do not have task names or have already been deleted.
-
DuplicateTaskNameError – If a task is repeated in the request.
-
Error-subclass on application errors.
-
- delete_tasks_async(task, rpc=None)source
Asynchronously deletes a task or list of tasks in this queue.
The task name is the only task attribute that is used to select tasks for deletion.
This function is identical to
Parametersdelete_tasks()
except that it returns an asynchronous object. You can callget_result()
on the return value to block on the call.-
task – A task instance or a list of task instances that will be deleted from the queue.
-
rpc – An optional UserRPC object.
A UserRPC object. Call
Raisesget_result()
to complete the RPC and obtain the task or list of tasks passed into this call.-
BadTaskStateError – If the tasks to be deleted do not have task names or have already been deleted.
-
DuplicateTaskNameError – If a task is repeated in the request.
-
- delete_tasks_by_name(task_name)source
Deletes a task or list of tasks in this queue, by name.
When multiple tasks are specified, an exception will be raised if any individual task fails to be deleted.
Parameterstask_name – A string corresponding to a task name, or an iterable of strings corresponding to task names.
ReturnsIf an iterable, other than string, is provided as input, a list of task objects is returned, one for each task name in the order requested. The
Task.was_deleted
property will beTrue
for each task deleted by this call, and will beFalse
for unknown and tombstoned tasks.Otherwise, if a single string was provided as input, a single task object is returned.
Raises-
DuplicateTaskNameError – If a task name is repeated in the request.
-
Error-subclass on application errors.
-
- delete_tasks_by_name_async(task_name, rpc=None)source
Asynchronously deletes a task or list of tasks in this queue, by name.
This function is identical to
Parametersdelete_tasks_by_name()
except that it returns an asynchronous object. You can callget_result()
on the return value to block on the call.-
task_name – A string corresponding to a task name, or an iterable of strings corresponding to task names.
-
rpc – An optional UserRPC object.
A UserRPC object. Call
get_result()
to complete the RPC and obtain the result.If an iterable, other than string, is provided as input, the result will be a list of of task objects, one for each task name in the order requested. The
Task.was_deleted
property will beTrue
for each task deleted by this call, and will beFalse
for unknown and tombstoned tasks.Otherwise, if a single string was provided as input, then the result will be a single task object.
RaisesDuplicateTaskNameError – If a task name is repeated in the request.
-
- fetch_statistics(deadline=10)source
Gets the current details about this queue.
Parametersdeadline – The maximum number of seconds to wait before aborting the method call.
ReturnsA
QueueStatistics
instance that contains information about this queue. Error-subclass on application errors.
- fetch_statistics_async(rpc=None)source
Asynchronously gets the current details about this queue.
Parametersrpc – An optional UserRPC object.
ReturnsA UserRPC object. Call
get_result()
to complete the RPC and obtain aQueueStatistics
instance that contains information about this queue.
- lease_tasks(lease_seconds, max_tasks, deadline=10)source
Leases a number of tasks from the queue for a period of time.
This method can only be performed on a pull queue. Any non-pull tasks in the pull queue will be converted into pull tasks when being leased. If fewer than the specified number of
Parametersmax_tasks
are available, all available tasks will be returned. Thelease_tasks
method supports leasing at most 1000 tasks for no longer than a week in a single call.-
lease_seconds – Number of seconds to lease the tasks, up to one week (604,800 seconds). Must be a positive integer.
-
max_tasks – The maximum number of tasks to lease from the pull queue, up to 1000 tasks.
-
deadline – The maximum number of seconds to wait before aborting the method call.
A list of tasks leased from the queue.
Raises-
InvalidLeaseTimeError – If
lease_seconds
is not a valid float or integer number or is outside the valid range. -
InvalidMaxTasksError – If
max_tasks
is not a valid integer or is outside the valid range. -
InvalidQueueModeError – If invoked on a queue that is not in pull mode.
-
Error-subclass on application errors.
-
- lease_tasks_async(lease_seconds, max_tasks, rpc=None)source
Asynchronously leases a number of tasks from the queue.
This method can only be performed on a pull queue. Attempts to lease tasks from a push queue results in an
InvalidQueueModeError
. All non-pull tasks in the pull queue will be converted into pull tasks when leased. If fewer than the specified value ofmax_tasks
are available, all available tasks on a best-effort basis are returned. Thelease_tasks_async
method supports leasing at most 1000 tasks for no longer than a week in a single call.This function is identical to
Parameterslease_tasks()
except that it returns an asynchronous object. You can callget_result()
on the return value to block on the call.-
lease_seconds – Number of seconds to lease the tasks, up to one week (604,800 seconds). Must be a positive integer.
-
max_tasks – Maximum number of tasks to lease from the pull queue, up to 1000 tasks.
-
rpc – An optional UserRPC object.
A UserRPC object. Call
Raisesget_result()
to complete the RPC and obtain the list of tasks leased from the queue.-
InvalidLeaseTimeError – If
lease_seconds
is not a valid float or integer number or is outside the valid range. -
InvalidMaxTasksError – If
max_tasks
is not a valid integer or is outside the valid range.
-
- lease_tasks_by_tag(lease_seconds, max_tasks, tag=None, deadline=10)source
Leases tasks with the same tag from the queue.
If a
tag
is specified, tasks with that tag are leased for a specified period of time. If atag
is not specified, the tag of the queue’s oldest task (specified by theeta
) will be used.This method can only be performed on a pull queue. Any non-pull tasks in the pull queue will be converted into pull tasks when being leased. If fewer than the specified value of
Parametersmax_tasks
are available, all available tasks will be returned. Thelease_tasks
method supports leasing at most 1000 tasks for no longer than a week in a single call.-
lease_seconds – Number of seconds to lease the tasks.
-
max_tasks – The maximum number of tasks to lease from the pull queue.
-
tag – The tag to query for, or None to group by the first available tag.
-
deadline – The maximum number of seconds to wait before aborting the method call.
A list of tasks leased from the queue.
Raises-
InvalidLeaseTimeError – If
lease_seconds
is not a valid float or integer number or is outside the valid range. -
InvalidMaxTasksError – If
max_tasks
is not a valid integer or is outside the valid range. -
InvalidQueueModeError – If invoked on a queue that is not in pull mode.
-
Error-subclass on application errors.
-
- lease_tasks_by_tag_async(lease_seconds, max_tasks, tag=None, rpc=None)source
Asynchronously leases tasks with the same tag from the queue.
If a
tag
is specified, tasks with that tag are leased for a specified period of time. If atag
is not specified, the best-effort oldest tag of the queue’s oldest task (specified by theeta
) will be used.This function is identical to
Parameterslease_tasks_by_tag()
except that it returns an asynchronous object. You can callget_result()
on the return value to block on the call.-
lease_seconds – Number of seconds to lease the tasks.
-
max_tasks – The maximum number of tasks to lease from the pull queue.
-
tag – The tag to query for, or None to group by the first available tag.
-
rpc – An optional UserRPC object.
A UserRPC object. Call
Raisesget_result()
to complete the RPC and obtain the list of tasks leased from the queue.-
InvalidLeaseTimeError – If
lease_seconds
is not a valid float or integer number or is outside the valid range. -
InvalidMaxTasksError – If
max_tasks
is not a valid integer or is outside the valid range.
-
- modify_task_lease(task, lease_seconds)source
Modifies the lease of a task in this queue.
Parameters-
task – A task instance that will have its lease modified.
-
lease_seconds – Number of seconds, from the current time, that the task lease will be modified to. If
lease_seconds
is0
, the task lease is removed and the task will be available for leasing again using thelease_tasks
method.
-
TypeError – If
lease_seconds
is not a valid float or integer. -
InvalidLeaseTimeError – If
lease_seconds
is outside of the valid range. -
Error-subclass on application errors.
-
- name
-
Returns the name of this queue.
- purge()source
Removes all of the tasks in this queue.
Purging the queue takes time, regardless of the queue size. Tasks continue to run until the backends recognize that the queue has been purged. This operation is permanent; purged tasks cannot be recovered.
RaisesError-subclass on application errors.
- class google.appengine.api.taskqueue.taskqueue.QueueStatistics(queue, tasks, oldest_eta_usec=None, executed_last_minute=None, in_flight=None, enforced_rate=None)source
-
Bases: object
Represents the current state of a queue.
- classmethod fetch(queue_or_queues, deadline=10)source
Get the queue details for multiple queues.
Use
QueueStatistics.fetch()
to getQueueStatistics
objects for the queues you are interested in. You can specify one or more queues.Example:
ParametersstatsList = taskqueue.QueueStatistics.fetch([taskqueue.Queue("foo"), taskqueue.Queue("bar")])
-
queue_or_queues – The queue or list of queues for which you are obtaining statistics. If you are retrieving statistics for a single queue, you can supply either a queue instance or the name of the queue. If you are retrieving statistics for a list of queues, you can supply an iterable list of queue instances or an iterable list of queue names.
-
deadline – The maximum number of seconds to wait before aborting the method call.
If an iterable (other than string) is provided as input, a list of of
QueueStatistics
objects will be returned, one for each queue in the order requested.Otherwise, if a single item was provided as input, then a single
RaisesQueueStatistics
object will be returned.-
TypeError – If
queue_or_queues
is not a queue instance, string, an iterable containing only queue instances, or an iterable containing only strings. -
Error-subclass on application errors.
-
- classmethod fetch_async(queue_or_queues, rpc=None)source
Asynchronously get the queue details for multiple queues.
Example:
Parametersrpc = taskqueue.create_rpc(deadline=1.0) taskqueue.QueueStatistics.fetch_async([taskqueue.Queue("foo"), taskqueue.Queue("bar")], rpc) statsList = rpc.get_result()
-
queue_or_queues – The queue or list of queues for which you are obtaining statistics. If you are retrieving statistics for a single queue, you can supply either a queue instance or the name of the queue. If you are retrieving a list of queues, you can supply an iterable list of queue instances or an iterable list of queue names.
-
rpc – An optional UserRPC object.
A UserRPC object. Call
get_result()
to complete the RPC and obtain the result.If an iterable (other than string) is provided as input, the result will be a list of of
QueueStatistics
objects, one for each queue in the order requested.Otherwise, if a single item was provided as input, then the result will be a single
RaisesQueueStatistics
object.TypeError – If
queue_or_queues
is not a queue instance, string, an iterable containing only queue instances, or an iterable containing only strings.-
- class google.appengine.api.taskqueue.taskqueue.Task(payload=None, **kwargs)source
-
Bases: object
Represents a single task on a queue.
The
Task
class enables an application to queue background work. Work is done through webhooks that process tasks pushed from a push queue, or workers that manually pull tasks from a pull queue.In push queues, most tasks are delivered in best-effort order of ETA.
Webhooks that fail cause tasks to be retried at a later time. You can configure the rate and number of retries for failed tasks. You can specify webhook URLs directly for push tasks. You can also use the default URL scheme, which translates task names into URLs that are relative to a queue’s base path. A default queue is also provided for simple usage.
In pull queues, workers are responsible for leasing tasks, processing them, and deleting them after processing. You can configure the number of task retries, which is based on how many times the task has been leased. You can define multiple queues with independent throttling controls.
You set the various properties for a task in the constructor. Once the
Task
object is instantiated, you insert that task into a queue. A task instance can be inserted into one queue only.- add(queue_name='default', transactional=False)source
-
Adds this task to a queue. See
Queue.add
.
- add_async(queue_name='default', transactional=False, rpc=None)source
-
Asynchronously adds this task to a queue. See
Queue.add_async
.
- eta
-
Returns a
datetime.datatime
when this task will run or be leased.
- eta_posix
-
Returns a POSIX timestamp of when this task will run or be leased.
- extract_params()source
Returns the parameters for this task.
If the same name parameter has several values, then the value is a list of strings. For
ReturnsPOST
requests and pull tasks, the parameters are extracted from the task payload; for all other methods, the parameters are extracted from the URL query string.A dictionary of strings that map parameter names to their values as strings. If the same name parameter has several values, the value will be a list of strings. For
RaisesPOST
requests and pull tasks, the parameters are extracted from the task payload. For all other methods, the parameters are extracted from the URL query string. An empty dictionary is returned if the task contains an empty payload or query string.ValueError – If the payload does not contain valid
application/x-www-form-urlencoded
data (forPOST
requests and pull tasks) or the URL does not contain a valid query (all other requests).
- headers
-
Returns a copy of the HTTP headers for this task (push tasks only).
- method
-
Returns the method to use for this task.
- name
-
Returns the name of this task.
- on_queue_url
-
Returns True if task runs on queue’s default URL (push tasks only).
- payload
-
Returns the payload to be used when the task is invoked (can be None).
- queue_name
-
Returns the name of the queue with which this task is associated.
- retry_count
-
Returns the number of retries or leases attempted on the task.
- retry_options
-
Returns any or all the
TaskRetryOptions
tasks.
- size
-
Returns the size of this task in bytes.
- tag
-
Returns the tag for this task.
- target
-
Returns the target for this task.
- url
-
Returns the relative URL for this task (push tasks only).
- was_deleted
-
Returns
True
if this task was successfully deleted.
- was_enqueued
-
Returns
True
if this task has been inserted into a queue.
- class google.appengine.api.taskqueue.taskqueue.TaskRetryOptions(**kwargs)source
-
Bases: object
The options used to decide when a failed task will be retried.
Tasks executing in the task queue can fail for many reasons. If a task fails to execute, which is indicated by returning any HTTP status code outside of the range 200-299, App Engine retries the task until it succeeds. By default, the system gradually reduces the retry rate to avoid flooding your application with too many requests, but schedules retry attempts to recur at a maximum of once per hour until the task succeeds. 503 errors, however, are treated as special cases and should not be returned by user code.
The
TaskRetryOptions
class provides the properties that you can use to decide when to retry a failed task at runtime.- max_backoff_seconds
-
The maximum number of seconds to wait before retrying a task.
- max_doublings
-
The number of times that the retry interval will be doubled.
- min_backoff_seconds
-
The minimum number of seconds to wait before retrying a task.
- task_age_limit
-
The number of seconds after which a failed task will not be retried.
- task_retry_limit
-
The number of times that a failed task will be retried.
- google.appengine.api.taskqueue.taskqueue.add(*args, **kwargs)source
Convenience method that creates a task and adds it to a queue.
All parameters are optional.
Push tasks cannot be added to queues in pull mode. Similarly, pull tasks cannot be added to queues in push mode.
Parameters-
payload – The payload data for this task that will be delivered to the webhook or backend as the HTTP request body (for push queues) or fetched by workers as part of the response from
lease_tasks()
(for pull queues). This argument is only allowed forPOST
andPUT
methods and pull tasks. -
queue_name – Name of queue to insert task into. If a name is not supplied, defaults to the default queue.
-
name – Name to give the task; if not specified, a name will be auto-generated when added to a queue and assigned to this object. The name must match the
_TASK_NAME_PATTERN
regular expression. -
method – Method to use when accessing the webhook; the default value is
POST
. Other accepted values areGET
,PUT
,DELETE
,HEAD
, orPULL
. Do not specify a method for push tasks, as the method will default toPOST
and post assigned tasks to the web hook at theurl
you specify. If you set themethod
toPULL
, the task will not be automatically delivered to the webhook; instead, it will remain in the queue until leased. -
url – Relative URL where the webhook that should handle this task is located for this application. You can use a query string unless this argument is used in a
POST
method. You cannot use this argument in a pull task. -
headers – Dictionary of headers to pass to the webhook. Values in the dictionary can be iterable to indicate repeated header fields. If you do not specify a
Content-Type
header for aPUSH
method, the default header (text/plain
) will be used. If you specify aHost
header for aPUSH
method, do not specify atarget
argument. You cannot use aheader
argument in a pull task. Any headers that use theX-AppEngine
prefix will also be dropped. -
params – Dictionary of parameters to use for this task. For
POST
and pull requests, the values in the dictionary can be iterable to indicate repeated parameters, and these parameters will be encoded asapplication/x-www-form-urlencoded
and set to the payload. For bothPOST
and pull requests, do not specify parameters if you have already specified a payload. ForPUT
requests, parameters are converted to a query string if the URL contains a query string, or if the task already has a payload. ForPUT
requests, do not specify parameters if the URL already contains a query string and the method isGET
. For all other methods, the parameters will be converted to a query string. -
transactional – Optional. If
True
, adds tasks if and only if the enclosing transaction is successfully committed. An error will be returned if this argument is set toTrue
in the absence of an enclosing transaction. IfFalse
, adds the tasks immediately, ignoring any enclosing transaction’s success or failure. -
countdown – Time in seconds into the future that this task should run or be leased. Defaults to zero. Do not specify this argument if you specified an
eta
. -
eta – A
datetime.datetime
that specifies the absolute earliest time at which the task should run. You cannot specify this argument if thecountdown
argument is specified. This argument can be time zone-aware or time zone-naive, or set to a time in the past. If the argument is set to None, the default value is now. For pull tasks, no worker can lease the task before the time indicated by theeta
argument. -
retry_options –
TaskRetryOptions
used to control when the task will be retried if it fails. For pull tasks, you can only specify thetask_retry_limit
option to specify the number of times that a task can be leased before it is deleted from the queue. For push tasks, you can specify themin_backoff_seconds
,max_backoff_seconds
,task_age_limit
,max_doublings
, andtask_retry_limit
options. -
tag – The tag to be used when grouping by tag (pull tasks only).
-
target – Push tasks only; specifies the alternate version or backend on which to run this task, or
DEFAULT_APP_VERSION
to run on the application’s default version. You can specify a module or version, a frontend version, or a backend on which to run this task. The string that you specify will be prepended to the domain name of your app. If you specify thetarget
argument, do not specify aHost
header in the dictionary for theheaders
argument.
The task that was added to the queue.
Raises-
BadTransactionStateError – If the transactional argument is true but this call is being made outside of the context of a transaction.
-
InvalidEtaError – If the
eta
is set too far into the future. -
InvalidQueueModeError – If a pull task is added to a queue in push mode, or a task with
method
not equal toPULL
is added to a queue in pull mode. -
InvalidTagError – If the tag is too long.
-
InvalidTaskError – If any of the parameters are invalid.
-
InvalidTaskNameError – If the task name is invalid.
-
InvalidUrlError – If the task URL is invalid or too long.
-
TaskTooLargeError – If the task with its associated payload is too large.
-
TransactionalRequestTooLargeError – If transactional is
True
and the total size of the tasks and supporting request data exceeds theMAX_TRANSACTIONAL_REQUEST_SIZE_BYTES
quota.
-
- google.appengine.api.taskqueue.taskqueue.create_rpc(deadline=None, callback=None)source
Creates an RPC object for use with the Task Queue API.
Parameters-
deadline – Optional deadline in seconds for the operation; the default value is a system-specific deadline, which is typically 5 seconds. After the deadline, a
DeadlineExceededError
error will be returned. -
callback – Optional function to be called with the Task Queue service returns results successfully when
get_result()
,check_success()
, orwait()
is invoked on the RPC object. The function is called without arguments. The function is not called in a background process or thread; the function is only called when one of the above methods is called by the application. The function is called even if the request fails or the RPC deadline elapses.
An
apiproxy_stub_map.UserRPC
object specialized for this service.-