google-cloud-longrunning 1.9.0

Google Cloud Client Libraries for Rust - Long Running Operations API
Documentation
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Long Running Operations API.
///
/// # Example
/// ```
/// # use google_cloud_longrunning::client::Operations;
/// use google_cloud_gax::paginator::ItemPaginator as _;
/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
///     let client = Operations::builder().build().await?;
///     let mut list = client.list_operations()
///         /* set fields */
///         .by_item();
///     while let Some(item) = list.next().await.transpose()? {
///         println!("{:?}", item);
///     }
/// # Ok(()) }
/// ```
///
/// # Service Description
///
/// Manages long-running operations with an API service.
///
/// When an API method normally takes long time to complete, it can be designed
/// to return [Operation][google.longrunning.Operation] to the client, and the
/// client can use this interface to receive the real response asynchronously by
/// polling the operation resource, or pass the operation resource to another API
/// (such as Pub/Sub API) to receive the response.  Any API service that returns
/// long-running operations should implement the `Operations` interface so
/// developers can have a consistent client experience.
///
/// [google.longrunning.Operation]: crate::model::Operation
///
/// # Configuration
///
/// To configure `Operations` use the `with_*` methods in the type returned
/// by [builder()][Operations::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://longrunning.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::operations::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::operations::ClientBuilder::with_credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `Operations` holds a connection pool internally, it is advised to
/// create one and reuse it. You do not need to wrap `Operations` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct Operations {
    inner: std::sync::Arc<dyn super::stub::dynamic::Operations>,
}

impl Operations {
    /// Returns a builder for [Operations].
    ///
    /// ```
    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
    /// # use google_cloud_longrunning::client::Operations;
    /// let client = Operations::builder().build().await?;
    /// # Ok(()) }
    /// ```
    pub fn builder() -> super::builder::operations::ClientBuilder {
        crate::new_client_builder(super::builder::operations::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::Operations + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::Operations>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::Operations> {
        super::transport::Operations::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> crate::ClientBuilderResult<impl super::stub::Operations> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::Operations::new)
    }

    /// Lists operations that match the specified filter in the request. If the
    /// server doesn't support this method, it returns `UNIMPLEMENTED`.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_longrunning::client::Operations;
    /// use google_cloud_gax::paginator::ItemPaginator as _;
    /// use google_cloud_longrunning::Result;
    /// async fn sample(
    ///    client: &Operations
    /// ) -> Result<()> {
    ///     let mut list = client.list_operations()
    ///         /* set fields */
    ///         .by_item();
    ///     while let Some(item) = list.next().await.transpose()? {
    ///         println!("{:?}", item);
    ///     }
    ///     Ok(())
    /// }
    /// ```
    pub fn list_operations(&self) -> super::builder::operations::ListOperations {
        super::builder::operations::ListOperations::new(self.inner.clone())
    }

    /// Gets the latest state of a long-running operation.  Clients can use this
    /// method to poll the operation result at intervals as recommended by the API
    /// service.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_longrunning::client::Operations;
    /// use google_cloud_longrunning::Result;
    /// async fn sample(
    ///    client: &Operations
    /// ) -> Result<()> {
    ///     let response = client.get_operation()
    ///         /* set fields */
    ///         .send().await?;
    ///     println!("response {:?}", response);
    ///     Ok(())
    /// }
    /// ```
    pub fn get_operation(&self) -> super::builder::operations::GetOperation {
        super::builder::operations::GetOperation::new(self.inner.clone())
    }

    /// Deletes a long-running operation. This method indicates that the client is
    /// no longer interested in the operation result. It does not cancel the
    /// operation. If the server doesn't support this method, it returns
    /// `google.rpc.Code.UNIMPLEMENTED`.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_longrunning::client::Operations;
    /// use google_cloud_longrunning::Result;
    /// async fn sample(
    ///    client: &Operations
    /// ) -> Result<()> {
    ///     client.delete_operation()
    ///         /* set fields */
    ///         .send().await?;
    ///     Ok(())
    /// }
    /// ```
    pub fn delete_operation(&self) -> super::builder::operations::DeleteOperation {
        super::builder::operations::DeleteOperation::new(self.inner.clone())
    }

    /// Starts asynchronous cancellation on a long-running operation.  The server
    /// makes a best effort to cancel the operation, but success is not
    /// guaranteed.  If the server doesn't support this method, it returns
    /// `google.rpc.Code.UNIMPLEMENTED`.  Clients can use
    /// [Operations.GetOperation][google.longrunning.Operations.GetOperation] or
    /// other methods to check whether the cancellation succeeded or whether the
    /// operation completed despite cancellation. On successful cancellation,
    /// the operation is not deleted; instead, it becomes an operation with
    /// an [Operation.error][google.longrunning.Operation.error] value with a
    /// [google.rpc.Status.code][google.rpc.Status.code] of `1`, corresponding to
    /// `Code.CANCELLED`.
    ///
    /// [google.longrunning.Operation.error]: crate::model::Operation::result
    /// [google.longrunning.Operations.GetOperation]: google-cloud-longrunning::client::Operations::get_operation
    /// [google.rpc.Status.code]: google_cloud_rpc::model::Status::code
    ///
    /// # Example
    /// ```
    /// # use google_cloud_longrunning::client::Operations;
    /// use google_cloud_longrunning::Result;
    /// async fn sample(
    ///    client: &Operations
    /// ) -> Result<()> {
    ///     client.cancel_operation()
    ///         /* set fields */
    ///         .send().await?;
    ///     Ok(())
    /// }
    /// ```
    pub fn cancel_operation(&self) -> super::builder::operations::CancelOperation {
        super::builder::operations::CancelOperation::new(self.inner.clone())
    }
}