google_cloud_tasks_v2/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 Cloud Tasks API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_tasks_v2::client::CloudTasks;
25/// let client = CloudTasks::builder().build().await?;
26/// // use `client` to make requests to the Cloud Tasks API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Cloud Tasks allows developers to manage the execution of background
33/// work in their applications.
34///
35/// # Configuration
36///
37/// To configure `CloudTasks` use the `with_*` methods in the type returned
38/// by [builder()][CloudTasks::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://cloudtasks.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::cloud_tasks::ClientBuilder::with_endpoint
51/// [with_credentials()]: super::builder::cloud_tasks::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/// `CloudTasks` holds a connection pool internally, it is advised to
58/// create one and the reuse it. You do not need to wrap `CloudTasks` 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 CloudTasks {
63 inner: std::sync::Arc<dyn super::stub::dynamic::CloudTasks>,
64}
65
66impl CloudTasks {
67 /// Returns a builder for [CloudTasks].
68 ///
69 /// ```
70 /// # tokio_test::block_on(async {
71 /// # use google_cloud_tasks_v2::client::CloudTasks;
72 /// let client = CloudTasks::builder().build().await?;
73 /// # gax::client_builder::Result::<()>::Ok(()) });
74 /// ```
75 pub fn builder() -> super::builder::cloud_tasks::ClientBuilder {
76 gax::client_builder::internal::new_builder(super::builder::cloud_tasks::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::CloudTasks + '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::CloudTasks>> {
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::CloudTasks> {
111 super::transport::CloudTasks::new(conf).await
112 }
113
114 async fn build_with_tracing(
115 conf: gaxi::options::ClientConfig,
116 ) -> gax::client_builder::Result<impl super::stub::CloudTasks> {
117 Self::build_transport(conf)
118 .await
119 .map(super::tracing::CloudTasks::new)
120 }
121
122 /// Lists queues.
123 ///
124 /// Queues are returned in lexicographical order.
125 pub fn list_queues(&self) -> super::builder::cloud_tasks::ListQueues {
126 super::builder::cloud_tasks::ListQueues::new(self.inner.clone())
127 }
128
129 /// Gets a queue.
130 pub fn get_queue(&self) -> super::builder::cloud_tasks::GetQueue {
131 super::builder::cloud_tasks::GetQueue::new(self.inner.clone())
132 }
133
134 /// Creates a queue.
135 ///
136 /// Queues created with this method allow tasks to live for a maximum of 31
137 /// days. After a task is 31 days old, the task will be deleted regardless of
138 /// whether it was dispatched or not.
139 ///
140 /// WARNING: Using this method may have unintended side effects if you are
141 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
142 /// Read
143 /// [Overview of Queue Management and
144 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
145 /// this method.
146 pub fn create_queue(&self) -> super::builder::cloud_tasks::CreateQueue {
147 super::builder::cloud_tasks::CreateQueue::new(self.inner.clone())
148 }
149
150 /// Updates a queue.
151 ///
152 /// This method creates the queue if it does not exist and updates
153 /// the queue if it does exist.
154 ///
155 /// Queues created with this method allow tasks to live for a maximum of 31
156 /// days. After a task is 31 days old, the task will be deleted regardless of
157 /// whether it was dispatched or not.
158 ///
159 /// WARNING: Using this method may have unintended side effects if you are
160 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
161 /// Read
162 /// [Overview of Queue Management and
163 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
164 /// this method.
165 pub fn update_queue(&self) -> super::builder::cloud_tasks::UpdateQueue {
166 super::builder::cloud_tasks::UpdateQueue::new(self.inner.clone())
167 }
168
169 /// Deletes a queue.
170 ///
171 /// This command will delete the queue even if it has tasks in it.
172 ///
173 /// Note: If you delete a queue, a queue with the same name can't be created
174 /// for 7 days.
175 ///
176 /// WARNING: Using this method may have unintended side effects if you are
177 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
178 /// Read
179 /// [Overview of Queue Management and
180 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
181 /// this method.
182 pub fn delete_queue(&self) -> super::builder::cloud_tasks::DeleteQueue {
183 super::builder::cloud_tasks::DeleteQueue::new(self.inner.clone())
184 }
185
186 /// Purges a queue by deleting all of its tasks.
187 ///
188 /// All tasks created before this method is called are permanently deleted.
189 ///
190 /// Purge operations can take up to one minute to take effect. Tasks
191 /// might be dispatched before the purge takes effect. A purge is irreversible.
192 pub fn purge_queue(&self) -> super::builder::cloud_tasks::PurgeQueue {
193 super::builder::cloud_tasks::PurgeQueue::new(self.inner.clone())
194 }
195
196 /// Pauses the queue.
197 ///
198 /// If a queue is paused then the system will stop dispatching tasks
199 /// until the queue is resumed via
200 /// [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. Tasks can
201 /// still be added when the queue is paused. A queue is paused if its
202 /// [state][google.cloud.tasks.v2.Queue.state] is
203 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
204 ///
205 /// [google.cloud.tasks.v2.CloudTasks.ResumeQueue]: crate::client::CloudTasks::resume_queue
206 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
207 /// [google.cloud.tasks.v2.Queue.state]: crate::model::Queue::state
208 pub fn pause_queue(&self) -> super::builder::cloud_tasks::PauseQueue {
209 super::builder::cloud_tasks::PauseQueue::new(self.inner.clone())
210 }
211
212 /// Resume a queue.
213 ///
214 /// This method resumes a queue after it has been
215 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or
216 /// [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The state of a
217 /// queue is stored in the queue's [state][google.cloud.tasks.v2.Queue.state];
218 /// after calling this method it will be set to
219 /// [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING].
220 ///
221 /// WARNING: Resuming many high-QPS queues at the same time can
222 /// lead to target overloading. If you are resuming high-QPS
223 /// queues, follow the 500/50/5 pattern described in
224 /// [Managing Cloud Tasks Scaling
225 /// Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
226 ///
227 /// [google.cloud.tasks.v2.Queue.State.DISABLED]: crate::model::queue::State::Disabled
228 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
229 /// [google.cloud.tasks.v2.Queue.State.RUNNING]: crate::model::queue::State::Running
230 /// [google.cloud.tasks.v2.Queue.state]: crate::model::Queue::state
231 pub fn resume_queue(&self) -> super::builder::cloud_tasks::ResumeQueue {
232 super::builder::cloud_tasks::ResumeQueue::new(self.inner.clone())
233 }
234
235 /// Gets the access control policy for a [Queue][google.cloud.tasks.v2.Queue].
236 /// Returns an empty policy if the resource exists and does not have a policy
237 /// set.
238 ///
239 /// Authorization requires the following
240 /// [Google IAM](https://cloud.google.com/iam) permission on the specified
241 /// resource parent:
242 ///
243 /// * `cloudtasks.queues.getIamPolicy`
244 ///
245 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
246 pub fn get_iam_policy(&self) -> super::builder::cloud_tasks::GetIamPolicy {
247 super::builder::cloud_tasks::GetIamPolicy::new(self.inner.clone())
248 }
249
250 /// Sets the access control policy for a [Queue][google.cloud.tasks.v2.Queue].
251 /// Replaces any existing policy.
252 ///
253 /// Note: The Cloud Console does not check queue-level IAM permissions yet.
254 /// Project-level permissions are required to use the Cloud Console.
255 ///
256 /// Authorization requires the following
257 /// [Google IAM](https://cloud.google.com/iam) permission on the specified
258 /// resource parent:
259 ///
260 /// * `cloudtasks.queues.setIamPolicy`
261 ///
262 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
263 pub fn set_iam_policy(&self) -> super::builder::cloud_tasks::SetIamPolicy {
264 super::builder::cloud_tasks::SetIamPolicy::new(self.inner.clone())
265 }
266
267 /// Returns permissions that a caller has on a
268 /// [Queue][google.cloud.tasks.v2.Queue]. If the resource does not exist, this
269 /// will return an empty set of permissions, not a
270 /// [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.
271 ///
272 /// Note: This operation is designed to be used for building permission-aware
273 /// UIs and command-line tools, not for authorization checking. This operation
274 /// may "fail open" without warning.
275 ///
276 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
277 pub fn test_iam_permissions(&self) -> super::builder::cloud_tasks::TestIamPermissions {
278 super::builder::cloud_tasks::TestIamPermissions::new(self.inner.clone())
279 }
280
281 /// Lists the tasks in a queue.
282 ///
283 /// By default, only the [BASIC][google.cloud.tasks.v2.Task.View.BASIC] view is
284 /// retrieved due to performance considerations;
285 /// [response_view][google.cloud.tasks.v2.ListTasksRequest.response_view]
286 /// controls the subset of information which is returned.
287 ///
288 /// The tasks may be returned in any order. The ordering may change at any
289 /// time.
290 ///
291 /// [google.cloud.tasks.v2.ListTasksRequest.response_view]: crate::model::ListTasksRequest::response_view
292 /// [google.cloud.tasks.v2.Task.View.BASIC]: crate::model::task::View::Basic
293 pub fn list_tasks(&self) -> super::builder::cloud_tasks::ListTasks {
294 super::builder::cloud_tasks::ListTasks::new(self.inner.clone())
295 }
296
297 /// Gets a task.
298 pub fn get_task(&self) -> super::builder::cloud_tasks::GetTask {
299 super::builder::cloud_tasks::GetTask::new(self.inner.clone())
300 }
301
302 /// Creates a task and adds it to a queue.
303 ///
304 /// Tasks cannot be updated after creation; there is no UpdateTask command.
305 ///
306 /// * The maximum task size is 100KB.
307 pub fn create_task(&self) -> super::builder::cloud_tasks::CreateTask {
308 super::builder::cloud_tasks::CreateTask::new(self.inner.clone())
309 }
310
311 /// Deletes a task.
312 ///
313 /// A task can be deleted if it is scheduled or dispatched. A task
314 /// cannot be deleted if it has executed successfully or permanently
315 /// failed.
316 pub fn delete_task(&self) -> super::builder::cloud_tasks::DeleteTask {
317 super::builder::cloud_tasks::DeleteTask::new(self.inner.clone())
318 }
319
320 /// Forces a task to run now.
321 ///
322 /// When this method is called, Cloud Tasks will dispatch the task, even if
323 /// the task is already running, the queue has reached its
324 /// [RateLimits][google.cloud.tasks.v2.RateLimits] or is
325 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
326 ///
327 /// This command is meant to be used for manual debugging. For
328 /// example, [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] can be used to
329 /// retry a failed task after a fix has been made or to manually force a task
330 /// to be dispatched now.
331 ///
332 /// The dispatched task is returned. That is, the task that is returned
333 /// contains the [status][Task.status] after the task is dispatched but
334 /// before the task is received by its target.
335 ///
336 /// If Cloud Tasks receives a successful response from the task's
337 /// target, then the task will be deleted; otherwise the task's
338 /// [schedule_time][google.cloud.tasks.v2.Task.schedule_time] will be reset to
339 /// the time that [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] was
340 /// called plus the retry delay specified in the queue's
341 /// [RetryConfig][google.cloud.tasks.v2.RetryConfig].
342 ///
343 /// [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] returns
344 /// [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a
345 /// task that has already succeeded or permanently failed.
346 ///
347 /// [google.cloud.tasks.v2.CloudTasks.RunTask]: crate::client::CloudTasks::run_task
348 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
349 /// [google.cloud.tasks.v2.RateLimits]: crate::model::RateLimits
350 /// [google.cloud.tasks.v2.RetryConfig]: crate::model::RetryConfig
351 /// [google.cloud.tasks.v2.Task.schedule_time]: crate::model::Task::schedule_time
352 pub fn run_task(&self) -> super::builder::cloud_tasks::RunTask {
353 super::builder::cloud_tasks::RunTask::new(self.inner.clone())
354 }
355
356 /// Lists information about the supported locations for this service.
357 pub fn list_locations(&self) -> super::builder::cloud_tasks::ListLocations {
358 super::builder::cloud_tasks::ListLocations::new(self.inner.clone())
359 }
360
361 /// Gets information about a location.
362 pub fn get_location(&self) -> super::builder::cloud_tasks::GetLocation {
363 super::builder::cloud_tasks::GetLocation::new(self.inner.clone())
364 }
365}