airflow.providers.google.cloud.hooks.tasks

This module contains a CloudTasksHook which allows you to connect to Google Cloud Tasks service, performing actions to queues or tasks.

Module Contents

Classes

CloudTasksHook

Hook for Google Cloud Tasks APIs. Cloud Tasks allows developers to manage

class airflow.providers.google.cloud.hooks.tasks.CloudTasksHook(gcp_conn_id='google_cloud_default', delegate_to=None, impersonation_chain=None)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Hook for Google Cloud Tasks APIs. Cloud Tasks allows developers to manage the execution of background work in their applications.

All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.

Parameters
  • gcp_conn_id (str) -- The connection ID to use when fetching connection info.

  • delegate_to (Optional[str]) -- The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled.

  • impersonation_chain (Optional[Union[str, Sequence[str]]]) -- Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account.

get_conn(self)[source]

Provides a client for interacting with the Google Cloud Tasks API.

Returns

Google Cloud Tasks API Client

Return type

google.cloud.tasks_v2.CloudTasksClient

create_queue(self, location, task_queue, project_id=PROVIDE_PROJECT_ID, queue_name=None, retry=None, timeout=None, metadata=())[source]

Creates a queue in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queue will be created.

  • task_queue (Union[dict, google.cloud.tasks_v2.types.Queue]) -- The task queue to create. Queue's name cannot be the same as an existing queue. If a dict is provided, it must be of the same form as the protobuf message Queue.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • queue_name (Optional[str]) -- (Optional) The queue's name. If provided, it will be used to construct the full queue path.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Queue

update_queue(self, task_queue, project_id=PROVIDE_PROJECT_ID, location=None, queue_name=None, update_mask=None, retry=None, timeout=None, metadata=())[source]

Updates a queue in Cloud Tasks.

Parameters
  • task_queue (google.cloud.tasks_v2.types.Queue) -- The task queue to update. This method creates the queue if it does not exist and updates the queue if it does exist. The queue's name must be specified.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • location (Optional[str]) -- (Optional) The location name in which the queue will be updated. If provided, it will be used to construct the full queue path.

  • queue_name (Optional[str]) -- (Optional) The queue's name. If provided, it will be used to construct the full queue path.

  • update_mask (Optional[google.protobuf.field_mask_pb2.FieldMask]) -- A mast used to specify which fields of the queue are being updated. If empty, then all fields will be updated. If a dict is provided, it must be of the same form as the protobuf message.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Queue

get_queue(self, location, queue_name, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]

Gets a queue from Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queue was created.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Queue

list_queues(self, location, project_id=PROVIDE_PROJECT_ID, results_filter=None, page_size=None, retry=None, timeout=None, metadata=())[source]

Lists queues from Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queues were created.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • results_filter (Optional[str]) -- (Optional) Filter used to specify a subset of queues.

  • page_size (Optional[int]) -- (Optional) The maximum number of resources contained in the underlying API response.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

list[google.cloud.tasks_v2.types.Queue]

delete_queue(self, location, queue_name, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]

Deletes a queue from Cloud Tasks, even if it has tasks in it.

Parameters
  • location (str) -- The location name in which the queue will be deleted.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

purge_queue(self, location, queue_name, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]

Purges a queue by deleting all of its tasks from Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queue will be purged.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

list[google.cloud.tasks_v2.types.Queue]

pause_queue(self, location, queue_name, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]

Pauses a queue in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queue will be paused.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

list[google.cloud.tasks_v2.types.Queue]

resume_queue(self, location, queue_name, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]

Resumes a queue in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the queue will be resumed.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

list[google.cloud.tasks_v2.types.Queue]

create_task(self, location, queue_name, task, project_id=PROVIDE_PROJECT_ID, task_name=None, response_view=None, retry=None, timeout=None, metadata=())[source]

Creates a task in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the task will be created.

  • queue_name (str) -- The queue's name.

  • task (Union[Dict, google.cloud.tasks_v2.types.Task]) -- The task to add. If a dict is provided, it must be of the same form as the protobuf message Task.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • task_name (Optional[str]) -- (Optional) The task's name. If provided, it will be used to construct the full task path.

  • response_view (Optional[google.cloud.tasks_v2.types.Task.View]) -- (Optional) This field specifies which subset of the Task will be returned.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Task

get_task(self, location, queue_name, task_name, project_id=PROVIDE_PROJECT_ID, response_view=None, retry=None, timeout=None, metadata=())[source]

Gets a task from Cloud Tasks.

Parameters
  • location (str) -- The location name in which the task was created.

  • queue_name (str) -- The queue's name.

  • task_name (str) -- The task's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • response_view (Optional[google.cloud.tasks_v2.types.Task.View]) -- (Optional) This field specifies which subset of the Task will be returned.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Task

list_tasks(self, location, queue_name, project_id, response_view=None, page_size=None, retry=None, timeout=None, metadata=())[source]

Lists the tasks in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the tasks were created.

  • queue_name (str) -- The queue's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • response_view (Optional[google.cloud.tasks_v2.types.Task.View]) -- (Optional) This field specifies which subset of the Task will be returned.

  • page_size (Optional[int]) -- (Optional) The maximum number of resources contained in the underlying API response.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

list[google.cloud.tasks_v2.types.Task]

delete_task(self, location, queue_name, task_name, project_id, retry=None, timeout=None, metadata=())[source]

Deletes a task from Cloud Tasks.

Parameters
  • location (str) -- The location name in which the task will be deleted.

  • queue_name (str) -- The queue's name.

  • task_name (str) -- The task's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

run_task(self, location, queue_name, task_name, project_id, response_view=None, retry=None, timeout=None, metadata=())[source]

Forces to run a task in Cloud Tasks.

Parameters
  • location (str) -- The location name in which the task was created.

  • queue_name (str) -- The queue's name.

  • task_name (str) -- The task's name.

  • project_id (str) -- (Optional) The ID of the Google Cloud project that owns the Cloud Tasks. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • response_view (Optional[google.cloud.tasks_v2.types.Task.View]) -- (Optional) This field specifies which subset of the Task will be returned.

  • retry (Optional[google.api_core.retry.Retry]) -- (Optional) A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- (Optional) The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- (Optional) Additional metadata that is provided to the method.

Return type

google.cloud.tasks_v2.types.Task

Was this entry helpful?