Skip to main content

google_cloud_workflows_v1/
client.rs

1// Copyright 2025 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#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::bare_urls)]
20
21/// Implements a client for the Workflows API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_workflows_v1::client::Workflows;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
28///     let client = Workflows::builder().build().await?;
29///     let parent = "parent_value";
30///     let mut list = client.list_workflows()
31///         .set_parent(parent)
32///         .by_item();
33///     while let Some(item) = list.next().await.transpose()? {
34///         println!("{:?}", item);
35///     }
36/// # Ok(()) }
37/// ```
38///
39/// # Service Description
40///
41/// Workflows is used to deploy and execute workflow programs.
42/// Workflows makes sure the program executes reliably, despite hardware and
43/// networking interruptions.
44///
45/// # Configuration
46///
47/// To configure `Workflows` use the `with_*` methods in the type returned
48/// by [builder()][Workflows::builder]. The default configuration should
49/// work for most applications. Common configuration changes include
50///
51/// * [with_endpoint()]: by default this client uses the global default endpoint
52///   (`https://workflows.googleapis.com`). Applications using regional
53///   endpoints or running in restricted networks (e.g. a network configured
54//    with [Private Google Access with VPC Service Controls]) may want to
55///   override this default.
56/// * [with_credentials()]: by default this client uses
57///   [Application Default Credentials]. Applications using custom
58///   authentication may need to override this default.
59///
60/// [with_endpoint()]: super::builder::workflows::ClientBuilder::with_endpoint
61/// [with_credentials()]: super::builder::workflows::ClientBuilder::with_credentials
62/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
63/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
64///
65/// # Pooling and Cloning
66///
67/// `Workflows` holds a connection pool internally, it is advised to
68/// create one and reuse it. You do not need to wrap `Workflows` in
69/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
70/// already uses an `Arc` internally.
71#[derive(Clone, Debug)]
72pub struct Workflows {
73    inner: std::sync::Arc<dyn super::stub::dynamic::Workflows>,
74}
75
76impl Workflows {
77    /// Returns a builder for [Workflows].
78    ///
79    /// ```
80    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
81    /// # use google_cloud_workflows_v1::client::Workflows;
82    /// let client = Workflows::builder().build().await?;
83    /// # Ok(()) }
84    /// ```
85    pub fn builder() -> super::builder::workflows::ClientBuilder {
86        crate::new_client_builder(super::builder::workflows::client::Factory)
87    }
88
89    /// Creates a new client from the provided stub.
90    ///
91    /// The most common case for calling this function is in tests mocking the
92    /// client's behavior.
93    pub fn from_stub<T>(stub: T) -> Self
94    where
95        T: super::stub::Workflows + 'static,
96    {
97        Self {
98            inner: std::sync::Arc::new(stub),
99        }
100    }
101
102    pub(crate) async fn new(
103        config: gaxi::options::ClientConfig,
104    ) -> crate::ClientBuilderResult<Self> {
105        let inner = Self::build_inner(config).await?;
106        Ok(Self { inner })
107    }
108
109    async fn build_inner(
110        conf: gaxi::options::ClientConfig,
111    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::Workflows>> {
112        if gaxi::options::tracing_enabled(&conf) {
113            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
114        }
115        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
116    }
117
118    async fn build_transport(
119        conf: gaxi::options::ClientConfig,
120    ) -> crate::ClientBuilderResult<impl super::stub::Workflows> {
121        super::transport::Workflows::new(conf).await
122    }
123
124    async fn build_with_tracing(
125        conf: gaxi::options::ClientConfig,
126    ) -> crate::ClientBuilderResult<impl super::stub::Workflows> {
127        Self::build_transport(conf)
128            .await
129            .map(super::tracing::Workflows::new)
130    }
131
132    /// Lists workflows in a given project and location.
133    /// The default order is not specified.
134    ///
135    /// # Example
136    /// ```
137    /// # use google_cloud_workflows_v1::client::Workflows;
138    /// use google_cloud_gax::paginator::ItemPaginator as _;
139    /// use google_cloud_workflows_v1::Result;
140    /// async fn sample(
141    ///    client: &Workflows, parent: &str
142    /// ) -> Result<()> {
143    ///     let mut list = client.list_workflows()
144    ///         .set_parent(parent)
145    ///         .by_item();
146    ///     while let Some(item) = list.next().await.transpose()? {
147    ///         println!("{:?}", item);
148    ///     }
149    ///     Ok(())
150    /// }
151    /// ```
152    pub fn list_workflows(&self) -> super::builder::workflows::ListWorkflows {
153        super::builder::workflows::ListWorkflows::new(self.inner.clone())
154    }
155
156    /// Gets details of a single workflow.
157    ///
158    /// # Example
159    /// ```
160    /// # use google_cloud_workflows_v1::client::Workflows;
161    /// use google_cloud_workflows_v1::Result;
162    /// async fn sample(
163    ///    client: &Workflows, name: &str
164    /// ) -> Result<()> {
165    ///     let response = client.get_workflow()
166    ///         .set_name(name)
167    ///         .send().await?;
168    ///     println!("response {:?}", response);
169    ///     Ok(())
170    /// }
171    /// ```
172    pub fn get_workflow(&self) -> super::builder::workflows::GetWorkflow {
173        super::builder::workflows::GetWorkflow::new(self.inner.clone())
174    }
175
176    /// Creates a new workflow. If a workflow with the specified name already
177    /// exists in the specified project and location, the long running operation
178    /// returns a [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error.
179    ///
180    /// # Long running operations
181    ///
182    /// This method is used to start, and/or poll a [long-running Operation].
183    /// The [Working with long-running operations] chapter in the [user guide]
184    /// covers these operations in detail.
185    ///
186    /// [long-running operation]: https://google.aip.dev/151
187    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
188    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
189    ///
190    /// # Example
191    /// ```
192    /// # use google_cloud_workflows_v1::client::Workflows;
193    /// use google_cloud_lro::Poller;
194    /// use google_cloud_workflows_v1::model::Workflow;
195    /// use google_cloud_workflows_v1::Result;
196    /// async fn sample(
197    ///    client: &Workflows, parent: &str
198    /// ) -> Result<()> {
199    ///     let response = client.create_workflow()
200    ///         .set_parent(parent)
201    ///         .set_workflow_id("workflow_id_value")
202    ///         .set_workflow(
203    ///             Workflow::new()/* set fields */
204    ///         )
205    ///         .poller().until_done().await?;
206    ///     println!("response {:?}", response);
207    ///     Ok(())
208    /// }
209    /// ```
210    pub fn create_workflow(&self) -> super::builder::workflows::CreateWorkflow {
211        super::builder::workflows::CreateWorkflow::new(self.inner.clone())
212    }
213
214    /// Deletes a workflow with the specified name.
215    /// This method also cancels and deletes all running executions of the
216    /// workflow.
217    ///
218    /// # Long running operations
219    ///
220    /// This method is used to start, and/or poll a [long-running Operation].
221    /// The [Working with long-running operations] chapter in the [user guide]
222    /// covers these operations in detail.
223    ///
224    /// [long-running operation]: https://google.aip.dev/151
225    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
226    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
227    ///
228    /// # Example
229    /// ```
230    /// # use google_cloud_workflows_v1::client::Workflows;
231    /// use google_cloud_lro::Poller;
232    /// use google_cloud_workflows_v1::Result;
233    /// async fn sample(
234    ///    client: &Workflows, name: &str
235    /// ) -> Result<()> {
236    ///     client.delete_workflow()
237    ///         .set_name(name)
238    ///         .poller().until_done().await?;
239    ///     Ok(())
240    /// }
241    /// ```
242    pub fn delete_workflow(&self) -> super::builder::workflows::DeleteWorkflow {
243        super::builder::workflows::DeleteWorkflow::new(self.inner.clone())
244    }
245
246    /// Updates an existing workflow.
247    /// Running this method has no impact on already running executions of the
248    /// workflow. A new revision of the workflow might be created as a result of a
249    /// successful update operation. In that case, the new revision is used
250    /// in new workflow executions.
251    ///
252    /// # Long running operations
253    ///
254    /// This method is used to start, and/or poll a [long-running Operation].
255    /// The [Working with long-running operations] chapter in the [user guide]
256    /// covers these operations in detail.
257    ///
258    /// [long-running operation]: https://google.aip.dev/151
259    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
260    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
261    ///
262    /// # Example
263    /// ```
264    /// # use google_cloud_workflows_v1::client::Workflows;
265    /// use google_cloud_lro::Poller;
266    /// # extern crate wkt as google_cloud_wkt;
267    /// use google_cloud_wkt::FieldMask;
268    /// use google_cloud_workflows_v1::model::Workflow;
269    /// use google_cloud_workflows_v1::Result;
270    /// async fn sample(
271    ///    client: &Workflows, name: &str
272    /// ) -> Result<()> {
273    ///     let response = client.update_workflow()
274    ///         .set_workflow(
275    ///             Workflow::new().set_name(name)/* set fields */
276    ///         )
277    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
278    ///         .poller().until_done().await?;
279    ///     println!("response {:?}", response);
280    ///     Ok(())
281    /// }
282    /// ```
283    pub fn update_workflow(&self) -> super::builder::workflows::UpdateWorkflow {
284        super::builder::workflows::UpdateWorkflow::new(self.inner.clone())
285    }
286
287    /// Lists revisions for a given workflow.
288    ///
289    /// # Example
290    /// ```
291    /// # use google_cloud_workflows_v1::client::Workflows;
292    /// use google_cloud_gax::paginator::ItemPaginator as _;
293    /// use google_cloud_workflows_v1::Result;
294    /// async fn sample(
295    ///    client: &Workflows
296    /// ) -> Result<()> {
297    ///     let mut list = client.list_workflow_revisions()
298    ///         /* set fields */
299    ///         .by_item();
300    ///     while let Some(item) = list.next().await.transpose()? {
301    ///         println!("{:?}", item);
302    ///     }
303    ///     Ok(())
304    /// }
305    /// ```
306    pub fn list_workflow_revisions(&self) -> super::builder::workflows::ListWorkflowRevisions {
307        super::builder::workflows::ListWorkflowRevisions::new(self.inner.clone())
308    }
309
310    /// Lists information about the supported locations for this service.
311    ///
312    /// # Example
313    /// ```
314    /// # use google_cloud_workflows_v1::client::Workflows;
315    /// use google_cloud_gax::paginator::ItemPaginator as _;
316    /// use google_cloud_workflows_v1::Result;
317    /// async fn sample(
318    ///    client: &Workflows
319    /// ) -> Result<()> {
320    ///     let mut list = client.list_locations()
321    ///         /* set fields */
322    ///         .by_item();
323    ///     while let Some(item) = list.next().await.transpose()? {
324    ///         println!("{:?}", item);
325    ///     }
326    ///     Ok(())
327    /// }
328    /// ```
329    pub fn list_locations(&self) -> super::builder::workflows::ListLocations {
330        super::builder::workflows::ListLocations::new(self.inner.clone())
331    }
332
333    /// Gets information about a location.
334    ///
335    /// # Example
336    /// ```
337    /// # use google_cloud_workflows_v1::client::Workflows;
338    /// use google_cloud_workflows_v1::Result;
339    /// async fn sample(
340    ///    client: &Workflows
341    /// ) -> Result<()> {
342    ///     let response = client.get_location()
343    ///         /* set fields */
344    ///         .send().await?;
345    ///     println!("response {:?}", response);
346    ///     Ok(())
347    /// }
348    /// ```
349    pub fn get_location(&self) -> super::builder::workflows::GetLocation {
350        super::builder::workflows::GetLocation::new(self.inner.clone())
351    }
352
353    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
354    ///
355    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
356    ///
357    /// # Example
358    /// ```
359    /// # use google_cloud_workflows_v1::client::Workflows;
360    /// use google_cloud_gax::paginator::ItemPaginator as _;
361    /// use google_cloud_workflows_v1::Result;
362    /// async fn sample(
363    ///    client: &Workflows
364    /// ) -> Result<()> {
365    ///     let mut list = client.list_operations()
366    ///         /* set fields */
367    ///         .by_item();
368    ///     while let Some(item) = list.next().await.transpose()? {
369    ///         println!("{:?}", item);
370    ///     }
371    ///     Ok(())
372    /// }
373    /// ```
374    pub fn list_operations(&self) -> super::builder::workflows::ListOperations {
375        super::builder::workflows::ListOperations::new(self.inner.clone())
376    }
377
378    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
379    ///
380    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
381    ///
382    /// # Example
383    /// ```
384    /// # use google_cloud_workflows_v1::client::Workflows;
385    /// use google_cloud_workflows_v1::Result;
386    /// async fn sample(
387    ///    client: &Workflows
388    /// ) -> Result<()> {
389    ///     let response = client.get_operation()
390    ///         /* set fields */
391    ///         .send().await?;
392    ///     println!("response {:?}", response);
393    ///     Ok(())
394    /// }
395    /// ```
396    pub fn get_operation(&self) -> super::builder::workflows::GetOperation {
397        super::builder::workflows::GetOperation::new(self.inner.clone())
398    }
399
400    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
401    ///
402    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
403    ///
404    /// # Example
405    /// ```
406    /// # use google_cloud_workflows_v1::client::Workflows;
407    /// use google_cloud_workflows_v1::Result;
408    /// async fn sample(
409    ///    client: &Workflows
410    /// ) -> Result<()> {
411    ///     client.delete_operation()
412    ///         /* set fields */
413    ///         .send().await?;
414    ///     Ok(())
415    /// }
416    /// ```
417    pub fn delete_operation(&self) -> super::builder::workflows::DeleteOperation {
418        super::builder::workflows::DeleteOperation::new(self.inner.clone())
419    }
420}