firebase_admin.functions module

Firebase Functions module.

Classes

TaskOptions

classfirebase_admin.functions.TaskOptions(schedule_delay_seconds:int|None=None,schedule_time:datetime|None=None,dispatch_deadline_seconds:int|None=None,task_id:str|None=None,headers:Dict[str,str]|None=None,uri:str|None=None)

Bases:object

Task Options that can be applied to a Task.

Parameters:
  • schedule_delay_seconds – The number of seconds after the current time at which to attempt orretry the task. Should only be set ifschedule_time is not set.

  • schedule_time – The time when the task is scheduled to be attempted or retried. Should onlybe set ifschedule_delay_seconds is not set.

  • dispatch_deadline_seconds – The deadline for requests sent to the worker. If the worker doesnot respond by this deadline then the request is cancelled and the attempt is marked asaDEADLINE_EXCEEDED failure. Cloud Tasks will retry the task according to theRetryConfig. The default is 10 minutes. The deadline must be in the range of 15seconds and 30 minutes (1800 seconds).

  • task_id

    The ID to use for the enqueued task. If not provided, one will be automaticallygenerated.

    If provided, an explicitly specified task ID enables task de-duplication.Task IDs should be strings that contain only letters ([A-Za-z]), numbers ([0-9]),hyphens (-), and underscores (_) with a maximum length of 500 characters. If a task’sID is identical to that of an existing task or a task that was deleted or executedrecently then the call will throw an error with codefunctions/task-already-exists.Another task with the same ID can’t be created for ~1hour after the original task wasdeleted or executed.

    Because there is an extra lookup cost to identify duplicate task IDs, setting IDsignificantly increases latency.

    Also, note that the infrastructure relies on an approximately uniform distributionof task IDs to store and serve tasks efficiently. For this reason, using hashed stringsfor the task ID or for the prefix of the task ID is recommended. Choosing task IDs thatare sequential or have sequential prefixes, for example using a timestamp, causes anincrease in latency and error rates in all task commands.

    Push IDs from the Firebase Realtime Database make poor IDs because they are based ontimestamps and will cause contention (slowdowns) in your task queue. Reversed push IDshowever form a perfect distribution and are an ideal key. To reverse a string in PythonusereversedString=someString[::-1]

  • headers

    HTTP request headers to include in the request to the task queue function. Theseheaders represent a subset of the headers that will accompany the task’s HTTP request.Some HTTP request headers will be ignored or replaced:Authorization,Host,Content-Length,User-Agent and others cannot be overridden.

    A complete list of these ignored or replaced headers can be found in the followingdefinition of the HttpRequest.headers property:https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks#httprequest

    By default, Content-Type is set to ‘application/json’.

    The size of the headers must be less than 80KB.

  • uri – The full URL that the request will be sent to. Must be a valid RFC3986 https orhttp URL.

dispatch_deadline_seconds:int|None=None
headers:Dict[str,str]|None=None
schedule_delay_seconds:int|None=None
schedule_time:datetime|None=None
task_id:str|None=None
uri:str|None=None

Functions

task_queue

firebase_admin.functions.task_queue(function_name:str,extension_id:str|None=None,app:App|None=None)TaskQueue

Creates a reference to a TaskQueue for a given function name.

The function name can be either:
  1. A fully qualified function resource name:

    projects/{project-id}/locations/{location-id}/functions/{function-name}

  2. A partial resource name with location and function name, in which case

    the runtime project ID is used:locations/{location-id}/functions/{function-name}

  3. A partial function name, in which case the runtime project ID and the

    default location,us-central1, is used:{function-name}

Parameters:
  • function_name – Name of the function.

  • extension_id – Firebase extension ID (optional).

  • app – An App instance (optional).

Returns:

A TaskQueue instance.

Return type:

TaskQueue

Raises:

ValueError – If the input arguments are invalid.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-12 UTC.