Skip to main content

CloudTasks

Struct CloudTasks 

Source
pub struct CloudTasks { /* private fields */ }
Expand description

Implements a client for the Cloud Tasks API.

§Example

use google_cloud_gax::paginator::ItemPaginator as _;
async fn sample(
   project_id: &str,
   location_id: &str,
) -> anyhow::Result<()> {
    let client = CloudTasks::builder().build().await?;
    let mut list = client.list_queues()
        .set_parent(format!("projects/{project_id}/locations/{location_id}"))
        .by_item();
    while let Some(item) = list.next().await.transpose()? {
        println!("{:?}", item);
    }
    Ok(())
}

§Service Description

Cloud Tasks allows developers to manage the execution of background work in their applications.

§Configuration

To configure CloudTasks use the with_* methods in the type returned by builder(). The default configuration should work for most applications. Common configuration changes include

§Pooling and Cloning

CloudTasks holds a connection pool internally, it is advised to create one and reuse it. You do not need to wrap CloudTasks in an Rc or Arc to reuse it, because it already uses an Arc internally.

Implementations§

Source§

impl CloudTasks

Source

pub fn builder() -> ClientBuilder

Returns a builder for CloudTasks.

let client = CloudTasks::builder().build().await?;
Source

pub fn from_stub<T>(stub: impl Into<Arc<T>>) -> Self
where T: CloudTasks + 'static,

Creates a new client from the provided stub.

The most common case for calling this function is in tests mocking the client’s behavior.

Source

pub fn list_queues(&self) -> ListQueues

Lists queues.

Queues are returned in lexicographical order.

§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str
) -> Result<()> {
    let mut list = client.list_queues()
        .set_parent(format!("projects/{project_id}/locations/{location_id}"))
        .by_item();
    while let Some(item) = list.next().await.transpose()? {
        println!("{:?}", item);
    }
    Ok(())
}
Source

pub fn get_queue(&self) -> GetQueue

Gets a queue.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
) -> Result<()> {
    let response = client.get_queue()
        .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn create_queue(&self) -> CreateQueue

Creates a queue.

Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.

WARNING: Using this method may have unintended side effects if you are using an App Engine queue.yaml or queue.xml file to manage your queues. Read Overview of Queue Management and queue.yaml before using this method.

§Example
use google_cloud_tasks_v2::model::Queue;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str
) -> Result<()> {
    let response = client.create_queue()
        .set_parent(format!("projects/{project_id}/locations/{location_id}"))
        .set_queue(
            Queue::new()/* set fields */
        )
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn update_queue(&self) -> UpdateQueue

Updates a queue.

This method creates the queue if it does not exist and updates the queue if it does exist.

Queues created with this method allow tasks to live for a maximum of 31 days. After a task is 31 days old, the task will be deleted regardless of whether it was dispatched or not.

WARNING: Using this method may have unintended side effects if you are using an App Engine queue.yaml or queue.xml file to manage your queues. Read Overview of Queue Management and queue.yaml before using this method.

§Example
use google_cloud_wkt::FieldMask;
use google_cloud_tasks_v2::model::Queue;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
) -> Result<()> {
    let response = client.update_queue()
        .set_queue(
            Queue::new().set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))/* set fields */
        )
        .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn delete_queue(&self) -> DeleteQueue

Deletes a queue.

This command will delete the queue even if it has tasks in it.

Note: If you delete a queue, you may be prevented from creating a new queue with the same name as the deleted queue for a tombstone window of up to 3 days. During this window, the CreateQueue operation may appear to recreate the queue, but this can be misleading. If you attempt to create a queue with the same name as one that is in the tombstone window, run GetQueue to confirm that the queue creation was successful. If GetQueue returns 200 response code, your queue was successfully created with the name of the previously deleted queue. Otherwise, your queue did not successfully recreate.

WARNING: Using this method may have unintended side effects if you are using an App Engine queue.yaml or queue.xml file to manage your queues. Read Overview of Queue Management and queue.yaml before using this method.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
) -> Result<()> {
    client.delete_queue()
        .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
        .send().await?;
    Ok(())
}
Source

pub fn purge_queue(&self) -> PurgeQueue

Purges a queue by deleting all of its tasks.

All tasks created before this method is called are permanently deleted.

Purge operations can take up to one minute to take effect. Tasks might be dispatched before the purge takes effect. A purge is irreversible.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.purge_queue()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn pause_queue(&self) -> PauseQueue

Pauses the queue.

If a queue is paused then the system will stop dispatching tasks until the queue is resumed via ResumeQueue. Tasks can still be added when the queue is paused. A queue is paused if its state is PAUSED.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.pause_queue()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn resume_queue(&self) -> ResumeQueue

Resume a queue.

This method resumes a queue after it has been PAUSED or DISABLED. The state of a queue is stored in the queue’s state; after calling this method it will be set to RUNNING.

WARNING: Resuming many high-QPS queues at the same time can lead to target overloading. If you are resuming high-QPS queues, follow the 500/50/5 pattern described in Managing Cloud Tasks Scaling Risks.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.resume_queue()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn get_iam_policy(&self) -> GetIamPolicy

Gets the access control policy for a Queue. Returns an empty policy if the resource exists and does not have a policy set.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.getIamPolicy
§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.get_iam_policy()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn set_iam_policy(&self) -> SetIamPolicy

Sets the access control policy for a Queue. Replaces any existing policy.

Note: The Cloud Console does not check queue-level IAM permissions yet. Project-level permissions are required to use the Cloud Console.

Authorization requires the following Google IAM permission on the specified resource parent:

  • cloudtasks.queues.setIamPolicy
§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.set_iam_policy()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn test_iam_permissions(&self) -> TestIamPermissions

Returns permissions that a caller has on a Queue. If the resource does not exist, this will return an empty set of permissions, not a [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may “fail open” without warning.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.test_iam_permissions()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn list_tasks(&self) -> ListTasks

Lists the tasks in a queue.

By default, only the BASIC view is retrieved due to performance considerations; response_view controls the subset of information which is returned.

The tasks may be returned in any order. The ordering may change at any time.

§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
) -> Result<()> {
    let mut list = client.list_tasks()
        .set_parent(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
        .by_item();
    while let Some(item) = list.next().await.transpose()? {
        println!("{:?}", item);
    }
    Ok(())
}
Source

pub fn get_task(&self) -> GetTask

Gets a task.

After a task is successfully executed or has exhausted its retry attempts, the task is deleted. A GetTask request for a deleted task returns a NOT_FOUND error.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str, task_id: &str
) -> Result<()> {
    let response = client.get_task()
        .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}/tasks/{task_id}"))
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn create_task(&self) -> CreateTask

Creates a task and adds it to a queue.

Tasks cannot be updated after creation; there is no UpdateTask command.

  • The maximum task size is 100KB.
§Example
use google_cloud_tasks_v2::model::Task;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
) -> Result<()> {
    let response = client.create_task()
        .set_parent(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
        .set_task(
            Task::new()/* set fields */
        )
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn batch_create_tasks(&self) -> BatchCreateTasks

Creates a batch of tasks and adds them to a queue.

All tasks must be for the same queue. A maximum of 100 tasks can be created in a single batch.

§Long running operations

This method is used to start, and/or poll a long-running Operation. The Working with long-running operations chapter in the user guide covers these operations in detail.

§Example
use google_cloud_lro::Poller;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.batch_create_tasks()
        /* set fields */
        .poller().until_done().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn delete_task(&self) -> DeleteTask

Deletes a task.

A task can be deleted if it is scheduled or dispatched. A task cannot be deleted if it has executed successfully or permanently failed.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str, task_id: &str
) -> Result<()> {
    client.delete_task()
        .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}/tasks/{task_id}"))
        .send().await?;
    Ok(())
}
Source

pub fn batch_delete_tasks(&self) -> BatchDeleteTasks

Deletes a batch of tasks. This is a non-atomic operation: if deletion fails for some tasks, it can still succeed for others. The metadata field of google.longrunning.Operation contains details of failed deletions. A maximum of 1000 tasks can be deleted in a batch.

§Long running operations

This method is used to start, and/or poll a long-running Operation. The Working with long-running operations chapter in the user guide covers these operations in detail.

§Example
use google_cloud_lro::Poller;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    client.batch_delete_tasks()
        /* set fields */
        .poller().until_done().await?;
    Ok(())
}
Source

pub fn run_task(&self) -> RunTask

Forces a task to run now.

When this method is called, Cloud Tasks will dispatch the task, even if the task is already running, the queue has reached its RateLimits or is PAUSED.

This command is meant to be used for manual debugging. For example, RunTask can be used to retry a failed task after a fix has been made or to manually force a task to be dispatched now.

If Cloud Tasks receives a successful response from the task’s target, then the task will be deleted; otherwise the task’s schedule_time will be reset to the time that RunTask was called plus the retry delay specified in the queue’s RetryConfig.

RunTask returns [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a task that has already succeeded or permanently failed.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.run_task()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn update_cmek_config(&self) -> UpdateCmekConfig

Creates or Updates a CMEK config.

Updates the Customer Managed Encryption Key associated with the Cloud Tasks location (Creates if the key does not already exist). All new tasks created in the location will be encrypted at-rest with the KMS-key provided in the config.

§Example
use google_cloud_wkt::FieldMask;
use google_cloud_tasks_v2::model::CmekConfig;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str
) -> Result<()> {
    let response = client.update_cmek_config()
        .set_cmek_config(
            CmekConfig::new().set_name(format!("projects/{project_id}/locations/{location_id}/cmekConfig"))/* set fields */
        )
        .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn get_cmek_config(&self) -> GetCmekConfig

Gets the CMEK config.

Gets the Customer Managed Encryption Key configured with the Cloud Tasks location. By default there is no kms_key configured.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks, project_id: &str, location_id: &str
) -> Result<()> {
    let response = client.get_cmek_config()
        .set_name(format!("projects/{project_id}/locations/{location_id}/cmekConfig"))
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn list_locations(&self) -> ListLocations

Lists information about the supported locations for this service.

This method lists locations based on the resource scope provided in the ListLocationsRequest.name field: * Global locations: If name is empty, the method lists the public locations available to all projects. * Project-specific locations: If name follows the format projects/{project}, the method lists locations visible to that specific project. This includes public, private, or other project-specific locations enabled for the project.

For gRPC and client library implementations, the resource name is passed as the name field. For direct service calls, the resource name is incorporated into the request path based on the specific service implementation and version.

§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let mut list = client.list_locations()
        /* set fields */
        .by_item();
    while let Some(item) = list.next().await.transpose()? {
        println!("{:?}", item);
    }
    Ok(())
}
Source

pub fn get_location(&self) -> GetLocation

Gets information about a location.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.get_location()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}
Source

pub fn get_operation(&self) -> GetOperation

Provides the Operations service functionality in this service.

§Example
use google_cloud_tasks_v2::Result;
async fn sample(
   client: &CloudTasks
) -> Result<()> {
    let response = client.get_operation()
        /* set fields */
        .send().await?;
    println!("response {:?}", response);
    Ok(())
}

Trait Implementations§

Source§

impl Clone for CloudTasks

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CloudTasks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more