firebase_admin.functions module

Firebase Functions module.

Classes

TaskOptions

class firebase_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 or retry the task. Should only be set if schedule_time is not set.

  • schedule_time – The time when the task is scheduled to be attempted or retried. Should only be set if schedule_delay_seconds is not set.

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

  • task_id

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

    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’s ID is identical to that of an existing task or a task that was deleted or executed recently then the call will throw an error with code functions/task-already-exists. Another task with the same ID can’t be created for ~1hour after the original task was deleted or executed.

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

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

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

  • headers

    HTTP request headers to include in the request to the task queue function. These headers 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 following definition 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 or http 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.