Skip to main content

google_cloud_workflows_executions_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::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Workflow Executions API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_workflows_executions_v1::client::Executions;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28///    parent: &str,
29/// ) -> anyhow::Result<()> {
30///     let client = Executions::builder().build().await?;
31///     let mut list = client.list_executions()
32///         .set_parent(parent)
33///         .by_item();
34///     while let Some(item) = list.next().await.transpose()? {
35///         println!("{:?}", item);
36///     }
37///     Ok(())
38/// }
39/// ```
40///
41/// # Service Description
42///
43/// Executions is used to start and manage running instances of
44/// [Workflows][google.cloud.workflows.v1.Workflow] called executions.
45///
46/// # Configuration
47///
48/// To configure `Executions` use the `with_*` methods in the type returned
49/// by [builder()][Executions::builder]. The default configuration should
50/// work for most applications. Common configuration changes include
51///
52/// * [with_endpoint()]: by default this client uses the global default endpoint
53///   (`https://workflowexecutions.googleapis.com`). Applications using regional
54///   endpoints or running in restricted networks (e.g. a network configured
55///   with [Private Google Access with VPC Service Controls]) may want to
56///   override this default.
57/// * [with_credentials()]: by default this client uses
58///   [Application Default Credentials]. Applications using custom
59///   authentication may need to override this default.
60///
61/// [with_endpoint()]: super::builder::executions::ClientBuilder::with_endpoint
62/// [with_credentials()]: super::builder::executions::ClientBuilder::with_credentials
63/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
64/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
65///
66/// # Pooling and Cloning
67///
68/// `Executions` holds a connection pool internally, it is advised to
69/// create one and reuse it. You do not need to wrap `Executions` in
70/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
71/// already uses an `Arc` internally.
72#[derive(Clone, Debug)]
73pub struct Executions {
74    inner: std::sync::Arc<dyn super::stub::dynamic::Executions>,
75}
76
77impl Executions {
78    /// Returns a builder for [Executions].
79    ///
80    /// ```
81    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82    /// # use google_cloud_workflows_executions_v1::client::Executions;
83    /// let client = Executions::builder().build().await?;
84    /// # Ok(()) }
85    /// ```
86    pub fn builder() -> super::builder::executions::ClientBuilder {
87        crate::new_client_builder(super::builder::executions::client::Factory)
88    }
89
90    /// Creates a new client from the provided stub.
91    ///
92    /// The most common case for calling this function is in tests mocking the
93    /// client's behavior.
94    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
95    where
96        T: super::stub::Executions + 'static,
97    {
98        Self { inner: stub.into() }
99    }
100
101    pub(crate) async fn new(
102        config: gaxi::options::ClientConfig,
103    ) -> crate::ClientBuilderResult<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    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::Executions>> {
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    ) -> crate::ClientBuilderResult<impl super::stub::Executions> {
120        super::transport::Executions::new(conf).await
121    }
122
123    async fn build_with_tracing(
124        conf: gaxi::options::ClientConfig,
125    ) -> crate::ClientBuilderResult<impl super::stub::Executions> {
126        Self::build_transport(conf)
127            .await
128            .map(super::tracing::Executions::new)
129    }
130
131    /// Returns a list of executions which belong to the workflow with
132    /// the given name. The method returns executions of all workflow
133    /// revisions. Returned executions are ordered by their start time (newest
134    /// first).
135    ///
136    /// # Example
137    /// ```
138    /// # use google_cloud_workflows_executions_v1::client::Executions;
139    /// use google_cloud_gax::paginator::ItemPaginator as _;
140    /// use google_cloud_workflows_executions_v1::Result;
141    /// async fn sample(
142    ///    client: &Executions, parent: &str
143    /// ) -> Result<()> {
144    ///     let mut list = client.list_executions()
145    ///         .set_parent(parent)
146    ///         .by_item();
147    ///     while let Some(item) = list.next().await.transpose()? {
148    ///         println!("{:?}", item);
149    ///     }
150    ///     Ok(())
151    /// }
152    /// ```
153    pub fn list_executions(&self) -> super::builder::executions::ListExecutions {
154        super::builder::executions::ListExecutions::new(self.inner.clone())
155    }
156
157    /// Creates a new execution using the latest revision of the given workflow.
158    ///
159    /// # Example
160    /// ```
161    /// # use google_cloud_workflows_executions_v1::client::Executions;
162    /// use google_cloud_workflows_executions_v1::model::Execution;
163    /// use google_cloud_workflows_executions_v1::Result;
164    /// async fn sample(
165    ///    client: &Executions, parent: &str
166    /// ) -> Result<()> {
167    ///     let response = client.create_execution()
168    ///         .set_parent(parent)
169    ///         .set_execution(
170    ///             Execution::new()/* set fields */
171    ///         )
172    ///         .send().await?;
173    ///     println!("response {:?}", response);
174    ///     Ok(())
175    /// }
176    /// ```
177    pub fn create_execution(&self) -> super::builder::executions::CreateExecution {
178        super::builder::executions::CreateExecution::new(self.inner.clone())
179    }
180
181    /// Returns an execution of the given name.
182    ///
183    /// # Example
184    /// ```
185    /// # use google_cloud_workflows_executions_v1::client::Executions;
186    /// use google_cloud_workflows_executions_v1::Result;
187    /// async fn sample(
188    ///    client: &Executions, project_id: &str, location_id: &str, workflow_id: &str, execution_id: &str
189    /// ) -> Result<()> {
190    ///     let response = client.get_execution()
191    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}/executions/{execution_id}"))
192    ///         .send().await?;
193    ///     println!("response {:?}", response);
194    ///     Ok(())
195    /// }
196    /// ```
197    pub fn get_execution(&self) -> super::builder::executions::GetExecution {
198        super::builder::executions::GetExecution::new(self.inner.clone())
199    }
200
201    /// Cancels an execution of the given name.
202    ///
203    /// # Example
204    /// ```
205    /// # use google_cloud_workflows_executions_v1::client::Executions;
206    /// use google_cloud_workflows_executions_v1::Result;
207    /// async fn sample(
208    ///    client: &Executions
209    /// ) -> Result<()> {
210    ///     let response = client.cancel_execution()
211    ///         /* set fields */
212    ///         .send().await?;
213    ///     println!("response {:?}", response);
214    ///     Ok(())
215    /// }
216    /// ```
217    pub fn cancel_execution(&self) -> super::builder::executions::CancelExecution {
218        super::builder::executions::CancelExecution::new(self.inner.clone())
219    }
220}