google_cloud_longrunning/client.rs
1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Long Running Operations API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_longrunning::client::Operations;
25/// let client = Operations::builder().build().await?;
26/// // use `client` to make requests to the Long Running Operations API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Manages long-running operations with an API service.
33///
34/// When an API method normally takes long time to complete, it can be designed
35/// to return [Operation][google.longrunning.Operation] to the client, and the
36/// client can use this interface to receive the real response asynchronously by
37/// polling the operation resource, or pass the operation resource to another API
38/// (such as Pub/Sub API) to receive the response. Any API service that returns
39/// long-running operations should implement the `Operations` interface so
40/// developers can have a consistent client experience.
41///
42/// [google.longrunning.Operation]: crate::model::Operation
43///
44/// # Configuration
45///
46/// To configure `Operations` use the `with_*` methods in the type returned
47/// by [builder()][Operations::builder]. The default configuration should
48/// work for most applications. Common configuration changes include
49///
50/// * [with_endpoint()]: by default this client uses the global default endpoint
51/// (`https://longrunning.googleapis.com`). Applications using regional
52/// endpoints or running in restricted networks (e.g. a network configured
53// with [Private Google Access with VPC Service Controls]) may want to
54/// override this default.
55/// * [with_credentials()]: by default this client uses
56/// [Application Default Credentials]. Applications using custom
57/// authentication may need to override this default.
58///
59/// [with_endpoint()]: super::builder::operations::ClientBuilder::with_endpoint
60/// [with_credentials()]: super::builder::operations::ClientBuilder::credentials
61/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
62/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
63///
64/// # Pooling and Cloning
65///
66/// `Operations` holds a connection pool internally, it is advised to
67/// create one and the reuse it. You do not need to wrap `Operations` in
68/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
69/// already uses an `Arc` internally.
70#[derive(Clone, Debug)]
71pub struct Operations {
72 inner: std::sync::Arc<dyn super::stub::dynamic::Operations>,
73}
74
75impl Operations {
76 /// Returns a builder for [Operations].
77 ///
78 /// ```
79 /// # tokio_test::block_on(async {
80 /// # use google_cloud_longrunning::client::Operations;
81 /// let client = Operations::builder().build().await?;
82 /// # gax::client_builder::Result::<()>::Ok(()) });
83 /// ```
84 pub fn builder() -> super::builder::operations::ClientBuilder {
85 gax::client_builder::internal::new_builder(super::builder::operations::client::Factory)
86 }
87
88 /// Creates a new client from the provided stub.
89 ///
90 /// The most common case for calling this function is in tests mocking the
91 /// client's behavior.
92 pub fn from_stub<T>(stub: T) -> Self
93 where
94 T: super::stub::Operations + 'static,
95 {
96 Self {
97 inner: std::sync::Arc::new(stub),
98 }
99 }
100
101 pub(crate) async fn new(
102 config: gaxi::options::ClientConfig,
103 ) -> gax::client_builder::Result<Self> {
104 let inner = Self::build_inner(config).await?;
105 Ok(Self { inner })
106 }
107
108 async fn build_inner(
109 conf: gaxi::options::ClientConfig,
110 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Operations>> {
111 if gaxi::options::tracing_enabled(&conf) {
112 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
113 }
114 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
115 }
116
117 async fn build_transport(
118 conf: gaxi::options::ClientConfig,
119 ) -> gax::client_builder::Result<impl super::stub::Operations> {
120 super::transport::Operations::new(conf).await
121 }
122
123 async fn build_with_tracing(
124 conf: gaxi::options::ClientConfig,
125 ) -> gax::client_builder::Result<impl super::stub::Operations> {
126 Self::build_transport(conf)
127 .await
128 .map(super::tracing::Operations::new)
129 }
130
131 /// Lists operations that match the specified filter in the request. If the
132 /// server doesn't support this method, it returns `UNIMPLEMENTED`.
133 pub fn list_operations(&self) -> super::builder::operations::ListOperations {
134 super::builder::operations::ListOperations::new(self.inner.clone())
135 }
136
137 /// Gets the latest state of a long-running operation. Clients can use this
138 /// method to poll the operation result at intervals as recommended by the API
139 /// service.
140 pub fn get_operation(&self) -> super::builder::operations::GetOperation {
141 super::builder::operations::GetOperation::new(self.inner.clone())
142 }
143
144 /// Deletes a long-running operation. This method indicates that the client is
145 /// no longer interested in the operation result. It does not cancel the
146 /// operation. If the server doesn't support this method, it returns
147 /// `google.rpc.Code.UNIMPLEMENTED`.
148 pub fn delete_operation(&self) -> super::builder::operations::DeleteOperation {
149 super::builder::operations::DeleteOperation::new(self.inner.clone())
150 }
151
152 /// Starts asynchronous cancellation on a long-running operation. The server
153 /// makes a best effort to cancel the operation, but success is not
154 /// guaranteed. If the server doesn't support this method, it returns
155 /// `google.rpc.Code.UNIMPLEMENTED`. Clients can use
156 /// [Operations.GetOperation][google.longrunning.Operations.GetOperation] or
157 /// other methods to check whether the cancellation succeeded or whether the
158 /// operation completed despite cancellation. On successful cancellation,
159 /// the operation is not deleted; instead, it becomes an operation with
160 /// an [Operation.error][google.longrunning.Operation.error] value with a
161 /// [google.rpc.Status.code][google.rpc.Status.code] of `1`, corresponding to
162 /// `Code.CANCELLED`.
163 ///
164 /// [google.longrunning.Operation.error]: crate::model::Operation::result
165 /// [google.longrunning.Operations.GetOperation]: crate::client::Operations::get_operation
166 /// [google.rpc.Status.code]: rpc::model::Status::code
167 pub fn cancel_operation(&self) -> super::builder::operations::CancelOperation {
168 super::builder::operations::CancelOperation::new(self.inner.clone())
169 }
170}