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::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Workflow Executions API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_workflows_executions_v1::client::Executions;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26///    parent: &str,
27/// ) -> anyhow::Result<()> {
28///     let client = Executions::builder().build().await?;
29///     let mut list = client.list_executions()
30///         .set_parent(parent)
31///         .by_item();
32///     while let Some(item) = list.next().await.transpose()? {
33///         println!("{:?}", item);
34///     }
35///     Ok(())
36/// }
37/// ```
38///
39/// # Service Description
40///
41/// Executions is used to start and manage running instances of
42/// [Workflows][google.cloud.workflows.v1.Workflow] called executions.
43///
44/// # Configuration
45///
46/// To configure `Executions` use the `with_*` methods in the type returned
47/// by [builder()][Executions::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://workflowexecutions.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::executions::ClientBuilder::with_endpoint
60/// [with_credentials()]: super::builder::executions::ClientBuilder::with_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/// `Executions` holds a connection pool internally, it is advised to
67/// create one and reuse it. You do not need to wrap `Executions` 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 Executions {
72    inner: std::sync::Arc<dyn super::stub::dynamic::Executions>,
73}
74
75impl Executions {
76    /// Returns a builder for [Executions].
77    ///
78    /// ```
79    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
80    /// # use google_cloud_workflows_executions_v1::client::Executions;
81    /// let client = Executions::builder().build().await?;
82    /// # Ok(()) }
83    /// ```
84    pub fn builder() -> super::builder::executions::ClientBuilder {
85        crate::new_client_builder(super::builder::executions::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: impl Into<std::sync::Arc<T>>) -> Self
93    where
94        T: super::stub::Executions + 'static,
95    {
96        Self { inner: stub.into() }
97    }
98
99    pub(crate) async fn new(
100        config: gaxi::options::ClientConfig,
101    ) -> crate::ClientBuilderResult<Self> {
102        let inner = Self::build_inner(config).await?;
103        Ok(Self { inner })
104    }
105
106    async fn build_inner(
107        conf: gaxi::options::ClientConfig,
108    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::Executions>> {
109        if gaxi::options::tracing_enabled(&conf) {
110            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111        }
112        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113    }
114
115    async fn build_transport(
116        conf: gaxi::options::ClientConfig,
117    ) -> crate::ClientBuilderResult<impl super::stub::Executions> {
118        super::transport::Executions::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> crate::ClientBuilderResult<impl super::stub::Executions> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::Executions::new)
127    }
128
129    /// Returns a list of executions which belong to the workflow with
130    /// the given name. The method returns executions of all workflow
131    /// revisions. Returned executions are ordered by their start time (newest
132    /// first).
133    ///
134    /// # Example
135    /// ```
136    /// # use google_cloud_workflows_executions_v1::client::Executions;
137    /// use google_cloud_gax::paginator::ItemPaginator as _;
138    /// use google_cloud_workflows_executions_v1::Result;
139    /// async fn sample(
140    ///    client: &Executions, parent: &str
141    /// ) -> Result<()> {
142    ///     let mut list = client.list_executions()
143    ///         .set_parent(parent)
144    ///         .by_item();
145    ///     while let Some(item) = list.next().await.transpose()? {
146    ///         println!("{:?}", item);
147    ///     }
148    ///     Ok(())
149    /// }
150    /// ```
151    pub fn list_executions(&self) -> super::builder::executions::ListExecutions {
152        super::builder::executions::ListExecutions::new(self.inner.clone())
153    }
154
155    /// Creates a new execution using the latest revision of the given workflow.
156    ///
157    /// # Example
158    /// ```
159    /// # use google_cloud_workflows_executions_v1::client::Executions;
160    /// use google_cloud_workflows_executions_v1::model::Execution;
161    /// use google_cloud_workflows_executions_v1::Result;
162    /// async fn sample(
163    ///    client: &Executions, parent: &str
164    /// ) -> Result<()> {
165    ///     let response = client.create_execution()
166    ///         .set_parent(parent)
167    ///         .set_execution(
168    ///             Execution::new()/* set fields */
169    ///         )
170    ///         .send().await?;
171    ///     println!("response {:?}", response);
172    ///     Ok(())
173    /// }
174    /// ```
175    pub fn create_execution(&self) -> super::builder::executions::CreateExecution {
176        super::builder::executions::CreateExecution::new(self.inner.clone())
177    }
178
179    /// Returns an execution of the given name.
180    ///
181    /// # Example
182    /// ```
183    /// # use google_cloud_workflows_executions_v1::client::Executions;
184    /// use google_cloud_workflows_executions_v1::Result;
185    /// async fn sample(
186    ///    client: &Executions, project_id: &str, location_id: &str, workflow_id: &str, execution_id: &str
187    /// ) -> Result<()> {
188    ///     let response = client.get_execution()
189    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}/executions/{execution_id}"))
190    ///         .send().await?;
191    ///     println!("response {:?}", response);
192    ///     Ok(())
193    /// }
194    /// ```
195    pub fn get_execution(&self) -> super::builder::executions::GetExecution {
196        super::builder::executions::GetExecution::new(self.inner.clone())
197    }
198
199    /// Cancels an execution of the given name.
200    ///
201    /// # Example
202    /// ```
203    /// # use google_cloud_workflows_executions_v1::client::Executions;
204    /// use google_cloud_workflows_executions_v1::Result;
205    /// async fn sample(
206    ///    client: &Executions
207    /// ) -> Result<()> {
208    ///     let response = client.cancel_execution()
209    ///         /* set fields */
210    ///         .send().await?;
211    ///     println!("response {:?}", response);
212    ///     Ok(())
213    /// }
214    /// ```
215    pub fn cancel_execution(&self) -> super::builder::executions::CancelExecution {
216        super::builder::executions::CancelExecution::new(self.inner.clone())
217    }
218}