Google Cloud Tasks API client library for managing distributed task queues.
—
Comprehensive queue lifecycle management including creation, configuration, monitoring, and control operations. Queues serve as containers for tasks with configurable rate limits, retry policies, and routing rules.
Retrieve queues within a location with optional filtering and pagination support.
def list_queues(
self,
request: Union[ListQueuesRequest, dict] = None,
*,
parent: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> pagers.ListQueuesPager:
"""List the queues in a location.
Args:
request: The request object or dictionary.
parent: Required. The location name (projects/PROJECT_ID/locations/LOCATION_ID).
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
An iterable of Queue resources.
"""Get detailed information about a specific queue.
def get_queue(
self,
request: Union[GetQueueRequest, dict] = None,
*,
name: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Get a queue.
Args:
request: The request object or dictionary.
name: Required. The resource name of the queue.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The queue object.
"""Create new queues with optional configuration for rate limits, retry policies, and routing.
def create_queue(
self,
request: Union[CreateQueueRequest, dict] = None,
*,
parent: str = None,
queue: Queue = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Create a queue.
Args:
request: The request object or dictionary.
parent: Required. The location where the queue will be created.
queue: Required. The queue to create.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The created queue.
"""Modify existing queue configuration including rate limits, retry settings, and routing rules.
def update_queue(
self,
request: Union[UpdateQueueRequest, dict] = None,
*,
queue: Queue = None,
update_mask: field_mask_pb2.FieldMask = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Update a queue.
Args:
request: The request object or dictionary.
queue: Required. The queue to update.
update_mask: A mask specifying which fields to update.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The updated queue.
"""Permanently remove queues and all contained tasks.
def delete_queue(
self,
request: Union[DeleteQueueRequest, dict] = None,
*,
name: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> None:
"""Delete a queue.
Args:
request: The request object or dictionary.
name: Required. The queue name to delete.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
"""Pause, resume, and purge queue operations for maintenance and task management.
def pause_queue(
self,
request: Union[PauseQueueRequest, dict] = None,
*,
name: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Pause a queue. Tasks are not dispatched while paused.
Args:
request: The request object or dictionary.
name: Required. The queue name to pause.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The paused queue.
"""
def resume_queue(
self,
request: Union[ResumeQueueRequest, dict] = None,
*,
name: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Resume a paused queue. Tasks can be dispatched again.
Args:
request: The request object or dictionary.
name: Required. The queue name to resume.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The resumed queue.
"""
def purge_queue(
self,
request: Union[PurgeQueueRequest, dict] = None,
*,
name: str = None,
retry: OptionalRetry = DEFAULT,
timeout: float = DEFAULT,
metadata: Sequence[Tuple[str, str]] = ()
) -> Queue:
"""Purge all tasks from a queue. This deletes all tasks.
Args:
request: The request object or dictionary.
name: Required. The queue name to purge.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request as metadata.
Returns:
The purged queue.
"""class ListQueuesRequest:
parent: str # Required. The location name
filter: str # Optional. Filter for queues
page_size: int # Maximum page size (max 9800)
page_token: str # Token for paginationclass GetQueueRequest:
name: str # Required. The resource name of the queueclass CreateQueueRequest:
parent: str # Required. The location where queue will be created
queue: Queue # Required. The queue to createclass UpdateQueueRequest:
queue: Queue # Required. The queue to update
update_mask: field_mask_pb2.FieldMask # Mask specifying fields to updateclass DeleteQueueRequest:
name: str # Required. The queue name to deleteclass PauseQueueRequest:
name: str # Required. The queue name to pauseclass ResumeQueueRequest:
name: str # Required. The queue name to resumeclass PurgeQueueRequest:
name: str # Required. The queue name to purgeclass ListQueuesResponse:
queues: MutableSequence[Queue] # List of queues
next_page_token: str # Token for next pagefrom google.cloud import tasks
from google.protobuf import duration_pb2
client = tasks.CloudTasksClient()
# Define paths
project = 'my-project-id'
location = 'us-central1'
queue_name = 'my-queue'
parent = client.common_location_path(project, location)
queue_path = client.queue_path(project, location, queue_name)
# Create a queue with rate limits and retry config
queue = tasks.Queue(
name=queue_path,
rate_limits=tasks.RateLimits(
max_dispatches_per_second=10.0,
max_concurrent_dispatches=5
),
retry_config=tasks.RetryConfig(
max_attempts=3,
max_retry_duration=duration_pb2.Duration(seconds=600),
min_backoff=duration_pb2.Duration(seconds=1),
max_backoff=duration_pb2.Duration(seconds=60)
)
)
created_queue = client.create_queue(parent=parent, queue=queue)
print(f'Created queue: {created_queue.name}')
# Get queue details
retrieved_queue = client.get_queue(name=queue_path)
print(f'Queue state: {retrieved_queue.state}')
# Pause the queue
paused_queue = client.pause_queue(name=queue_path)
print(f'Queue paused: {paused_queue.state == tasks.Queue.State.PAUSED}')
# Resume the queue
resumed_queue = client.resume_queue(name=queue_path)
print(f'Queue resumed: {resumed_queue.state == tasks.Queue.State.RUNNING}')from google.cloud import tasks
client = tasks.CloudTasksClient()
parent = client.common_location_path('my-project-id', 'us-central1')
# List all queues
for queue in client.list_queues(parent=parent):
print(f'Queue: {queue.name}, State: {queue.state}')
# List with filtering (if supported)
filtered_queues = client.list_queues(
parent=parent,
filter='state=RUNNING'
)
for queue in filtered_queues:
print(f'Running queue: {queue.name}')
# List with pagination
page_result = client.list_queues(parent=parent, page_size=10)
for queue in page_result:
print(f'Queue: {queue.name}')from google.cloud import tasks
from google.protobuf import field_mask_pb2
client = tasks.CloudTasksClient()
queue_path = client.queue_path('my-project-id', 'us-central1', 'my-queue')
# Get current queue
current_queue = client.get_queue(name=queue_path)
# Update rate limits
current_queue.rate_limits.max_dispatches_per_second = 20.0
current_queue.rate_limits.max_concurrent_dispatches = 10
# Specify which fields to update
update_mask = field_mask_pb2.FieldMask(
paths=['rate_limits.max_dispatches_per_second', 'rate_limits.max_concurrent_dispatches']
)
updated_queue = client.update_queue(queue=current_queue, update_mask=update_mask)
print(f'Updated queue rate limits: {updated_queue.rate_limits.max_dispatches_per_second}')Install with Tessl CLI
npx tessl i tessl/pypi-google-cloud-tasks