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/// # tokio_test::block_on(async {
24/// # use google_cloud_workflows_executions_v1::client::Executions;
25/// let client = Executions::builder().build().await?;
26/// // use `client` to make requests to the Workflow Executions API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Executions is used to start and manage running instances of
33/// [Workflows][google.cloud.workflows.v1.Workflow] called executions.
34///
35/// # Configuration
36///
37/// To configure `Executions` use the `with_*` methods in the type returned
38/// by [builder()][Executions::builder]. The default configuration should
39/// work for most applications. Common configuration changes include
40///
41/// * [with_endpoint()]: by default this client uses the global default endpoint
42///   (`https://workflowexecutions.googleapis.com`). Applications using regional
43///   endpoints or running in restricted networks (e.g. a network configured
44//    with [Private Google Access with VPC Service Controls]) may want to
45///   override this default.
46/// * [with_credentials()]: by default this client uses
47///   [Application Default Credentials]. Applications using custom
48///   authentication may need to override this default.
49///
50/// [with_endpoint()]: super::builder::executions::ClientBuilder::with_endpoint
51/// [with_credentials()]: super::builder::executions::ClientBuilder::credentials
52/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
53/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
54///
55/// # Pooling and Cloning
56///
57/// `Executions` holds a connection pool internally, it is advised to
58/// create one and the reuse it.  You do not need to wrap `Executions` in
59/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
60/// already uses an `Arc` internally.
61#[derive(Clone, Debug)]
62pub struct Executions {
63    inner: std::sync::Arc<dyn super::stub::dynamic::Executions>,
64}
65
66impl Executions {
67    /// Returns a builder for [Executions].
68    ///
69    /// ```
70    /// # tokio_test::block_on(async {
71    /// # use google_cloud_workflows_executions_v1::client::Executions;
72    /// let client = Executions::builder().build().await?;
73    /// # gax::client_builder::Result::<()>::Ok(()) });
74    /// ```
75    pub fn builder() -> super::builder::executions::ClientBuilder {
76        gax::client_builder::internal::new_builder(super::builder::executions::client::Factory)
77    }
78
79    /// Creates a new client from the provided stub.
80    ///
81    /// The most common case for calling this function is in tests mocking the
82    /// client's behavior.
83    pub fn from_stub<T>(stub: T) -> Self
84    where
85        T: super::stub::Executions + 'static,
86    {
87        Self {
88            inner: std::sync::Arc::new(stub),
89        }
90    }
91
92    pub(crate) async fn new(
93        config: gaxi::options::ClientConfig,
94    ) -> gax::client_builder::Result<Self> {
95        let inner = Self::build_inner(config).await?;
96        Ok(Self { inner })
97    }
98
99    async fn build_inner(
100        conf: gaxi::options::ClientConfig,
101    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Executions>> {
102        if gaxi::options::tracing_enabled(&conf) {
103            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
104        }
105        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
106    }
107
108    async fn build_transport(
109        conf: gaxi::options::ClientConfig,
110    ) -> gax::client_builder::Result<impl super::stub::Executions> {
111        super::transport::Executions::new(conf).await
112    }
113
114    async fn build_with_tracing(
115        conf: gaxi::options::ClientConfig,
116    ) -> gax::client_builder::Result<impl super::stub::Executions> {
117        Self::build_transport(conf)
118            .await
119            .map(super::tracing::Executions::new)
120    }
121
122    /// Returns a list of executions which belong to the workflow with
123    /// the given name. The method returns executions of all workflow
124    /// revisions. Returned executions are ordered by their start time (newest
125    /// first).
126    pub fn list_executions(&self) -> super::builder::executions::ListExecutions {
127        super::builder::executions::ListExecutions::new(self.inner.clone())
128    }
129
130    /// Creates a new execution using the latest revision of the given workflow.
131    pub fn create_execution(&self) -> super::builder::executions::CreateExecution {
132        super::builder::executions::CreateExecution::new(self.inner.clone())
133    }
134
135    /// Returns an execution of the given name.
136    pub fn get_execution(&self) -> super::builder::executions::GetExecution {
137        super::builder::executions::GetExecution::new(self.inner.clone())
138    }
139
140    /// Cancels an execution of the given name.
141    pub fn cancel_execution(&self) -> super::builder::executions::CancelExecution {
142        super::builder::executions::CancelExecution::new(self.inner.clone())
143    }
144}