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::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 Cloud Tasks API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_tasks_v2::client::CloudTasks;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// project_id: &str,
29/// location_id: &str,
30/// ) -> anyhow::Result<()> {
31/// let client = CloudTasks::builder().build().await?;
32/// let mut list = client.list_queues()
33/// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
34/// .by_item();
35/// while let Some(item) = list.next().await.transpose()? {
36/// println!("{:?}", item);
37/// }
38/// Ok(())
39/// }
40/// ```
41///
42/// # Service Description
43///
44/// Cloud Tasks allows developers to manage the execution of background
45/// work in their applications.
46///
47/// # Configuration
48///
49/// To configure `CloudTasks` use the `with_*` methods in the type returned
50/// by [builder()][CloudTasks::builder]. The default configuration should
51/// work for most applications. Common configuration changes include
52///
53/// * [with_endpoint()]: by default this client uses the global default endpoint
54/// (`https://cloudtasks.googleapis.com`). Applications using regional
55/// endpoints or running in restricted networks (e.g. a network configured
56/// with [Private Google Access with VPC Service Controls]) may want to
57/// override this default.
58/// * [with_credentials()]: by default this client uses
59/// [Application Default Credentials]. Applications using custom
60/// authentication may need to override this default.
61///
62/// [with_endpoint()]: super::builder::cloud_tasks::ClientBuilder::with_endpoint
63/// [with_credentials()]: super::builder::cloud_tasks::ClientBuilder::with_credentials
64/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
65/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
66///
67/// # Pooling and Cloning
68///
69/// `CloudTasks` holds a connection pool internally, it is advised to
70/// create one and reuse it. You do not need to wrap `CloudTasks` in
71/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
72/// already uses an `Arc` internally.
73#[derive(Clone, Debug)]
74pub struct CloudTasks {
75 inner: std::sync::Arc<dyn super::stub::dynamic::CloudTasks>,
76}
77
78impl CloudTasks {
79 /// Returns a builder for [CloudTasks].
80 ///
81 /// ```
82 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
83 /// # use google_cloud_tasks_v2::client::CloudTasks;
84 /// let client = CloudTasks::builder().build().await?;
85 /// # Ok(()) }
86 /// ```
87 pub fn builder() -> super::builder::cloud_tasks::ClientBuilder {
88 crate::new_client_builder(super::builder::cloud_tasks::client::Factory)
89 }
90
91 /// Creates a new client from the provided stub.
92 ///
93 /// The most common case for calling this function is in tests mocking the
94 /// client's behavior.
95 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
96 where
97 T: super::stub::CloudTasks + 'static,
98 {
99 Self { inner: stub.into() }
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::CloudTasks>> {
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::CloudTasks> {
121 super::transport::CloudTasks::new(conf).await
122 }
123
124 async fn build_with_tracing(
125 conf: gaxi::options::ClientConfig,
126 ) -> crate::ClientBuilderResult<impl super::stub::CloudTasks> {
127 Self::build_transport(conf)
128 .await
129 .map(super::tracing::CloudTasks::new)
130 }
131
132 /// Lists queues.
133 ///
134 /// Queues are returned in lexicographical order.
135 ///
136 /// # Example
137 /// ```
138 /// # use google_cloud_tasks_v2::client::CloudTasks;
139 /// use google_cloud_gax::paginator::ItemPaginator as _;
140 /// use google_cloud_tasks_v2::Result;
141 /// async fn sample(
142 /// client: &CloudTasks, project_id: &str, location_id: &str
143 /// ) -> Result<()> {
144 /// let mut list = client.list_queues()
145 /// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
146 /// .by_item();
147 /// while let Some(item) = list.next().await.transpose()? {
148 /// println!("{:?}", item);
149 /// }
150 /// Ok(())
151 /// }
152 /// ```
153 pub fn list_queues(&self) -> super::builder::cloud_tasks::ListQueues {
154 super::builder::cloud_tasks::ListQueues::new(self.inner.clone())
155 }
156
157 /// Gets a queue.
158 ///
159 /// # Example
160 /// ```
161 /// # use google_cloud_tasks_v2::client::CloudTasks;
162 /// use google_cloud_tasks_v2::Result;
163 /// async fn sample(
164 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
165 /// ) -> Result<()> {
166 /// let response = client.get_queue()
167 /// .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
168 /// .send().await?;
169 /// println!("response {:?}", response);
170 /// Ok(())
171 /// }
172 /// ```
173 pub fn get_queue(&self) -> super::builder::cloud_tasks::GetQueue {
174 super::builder::cloud_tasks::GetQueue::new(self.inner.clone())
175 }
176
177 /// Creates a queue.
178 ///
179 /// Queues created with this method allow tasks to live for a maximum of 31
180 /// days. After a task is 31 days old, the task will be deleted regardless of
181 /// whether it was dispatched or not.
182 ///
183 /// WARNING: Using this method may have unintended side effects if you are
184 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
185 /// Read
186 /// [Overview of Queue Management and
187 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
188 /// this method.
189 ///
190 /// # Example
191 /// ```
192 /// # use google_cloud_tasks_v2::client::CloudTasks;
193 /// use google_cloud_tasks_v2::model::Queue;
194 /// use google_cloud_tasks_v2::Result;
195 /// async fn sample(
196 /// client: &CloudTasks, project_id: &str, location_id: &str
197 /// ) -> Result<()> {
198 /// let response = client.create_queue()
199 /// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
200 /// .set_queue(
201 /// Queue::new()/* set fields */
202 /// )
203 /// .send().await?;
204 /// println!("response {:?}", response);
205 /// Ok(())
206 /// }
207 /// ```
208 pub fn create_queue(&self) -> super::builder::cloud_tasks::CreateQueue {
209 super::builder::cloud_tasks::CreateQueue::new(self.inner.clone())
210 }
211
212 /// Updates a queue.
213 ///
214 /// This method creates the queue if it does not exist and updates
215 /// the queue if it does exist.
216 ///
217 /// Queues created with this method allow tasks to live for a maximum of 31
218 /// days. After a task is 31 days old, the task will be deleted regardless of
219 /// whether it was dispatched or not.
220 ///
221 /// WARNING: Using this method may have unintended side effects if you are
222 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
223 /// Read
224 /// [Overview of Queue Management and
225 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
226 /// this method.
227 ///
228 /// # Example
229 /// ```
230 /// # use google_cloud_tasks_v2::client::CloudTasks;
231 /// # extern crate wkt as google_cloud_wkt;
232 /// use google_cloud_wkt::FieldMask;
233 /// use google_cloud_tasks_v2::model::Queue;
234 /// use google_cloud_tasks_v2::Result;
235 /// async fn sample(
236 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
237 /// ) -> Result<()> {
238 /// let response = client.update_queue()
239 /// .set_queue(
240 /// Queue::new().set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))/* set fields */
241 /// )
242 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
243 /// .send().await?;
244 /// println!("response {:?}", response);
245 /// Ok(())
246 /// }
247 /// ```
248 pub fn update_queue(&self) -> super::builder::cloud_tasks::UpdateQueue {
249 super::builder::cloud_tasks::UpdateQueue::new(self.inner.clone())
250 }
251
252 /// Deletes a queue.
253 ///
254 /// This command will delete the queue even if it has tasks in it.
255 ///
256 /// Note: If you delete a queue, you may be prevented from creating a new queue
257 /// with the same name as the deleted queue for a tombstone window of up to
258 /// 3 days. During this window, the CreateQueue operation may appear to
259 /// recreate the queue, but this can be misleading. If you attempt to create
260 /// a queue with the same name as one that is in the tombstone window, run
261 /// GetQueue to confirm that the queue creation was successful. If GetQueue
262 /// returns 200 response code, your queue was successfully created with the
263 /// name of the previously deleted queue. Otherwise, your queue did not
264 /// successfully recreate.
265 ///
266 /// WARNING: Using this method may have unintended side effects if you are
267 /// using an App Engine `queue.yaml` or `queue.xml` file to manage your queues.
268 /// Read
269 /// [Overview of Queue Management and
270 /// queue.yaml](https://cloud.google.com/tasks/docs/queue-yaml) before using
271 /// this method.
272 ///
273 /// # Example
274 /// ```
275 /// # use google_cloud_tasks_v2::client::CloudTasks;
276 /// use google_cloud_tasks_v2::Result;
277 /// async fn sample(
278 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
279 /// ) -> Result<()> {
280 /// client.delete_queue()
281 /// .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
282 /// .send().await?;
283 /// Ok(())
284 /// }
285 /// ```
286 pub fn delete_queue(&self) -> super::builder::cloud_tasks::DeleteQueue {
287 super::builder::cloud_tasks::DeleteQueue::new(self.inner.clone())
288 }
289
290 /// Purges a queue by deleting all of its tasks.
291 ///
292 /// All tasks created before this method is called are permanently deleted.
293 ///
294 /// Purge operations can take up to one minute to take effect. Tasks
295 /// might be dispatched before the purge takes effect. A purge is irreversible.
296 ///
297 /// # Example
298 /// ```
299 /// # use google_cloud_tasks_v2::client::CloudTasks;
300 /// use google_cloud_tasks_v2::Result;
301 /// async fn sample(
302 /// client: &CloudTasks
303 /// ) -> Result<()> {
304 /// let response = client.purge_queue()
305 /// /* set fields */
306 /// .send().await?;
307 /// println!("response {:?}", response);
308 /// Ok(())
309 /// }
310 /// ```
311 pub fn purge_queue(&self) -> super::builder::cloud_tasks::PurgeQueue {
312 super::builder::cloud_tasks::PurgeQueue::new(self.inner.clone())
313 }
314
315 /// Pauses the queue.
316 ///
317 /// If a queue is paused then the system will stop dispatching tasks
318 /// until the queue is resumed via
319 /// [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. Tasks can
320 /// still be added when the queue is paused. A queue is paused if its
321 /// [state][google.cloud.tasks.v2.Queue.state] is
322 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
323 ///
324 /// [google.cloud.tasks.v2.CloudTasks.ResumeQueue]: crate::client::CloudTasks::resume_queue
325 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
326 /// [google.cloud.tasks.v2.Queue.state]: crate::model::Queue::state
327 ///
328 /// # Example
329 /// ```
330 /// # use google_cloud_tasks_v2::client::CloudTasks;
331 /// use google_cloud_tasks_v2::Result;
332 /// async fn sample(
333 /// client: &CloudTasks
334 /// ) -> Result<()> {
335 /// let response = client.pause_queue()
336 /// /* set fields */
337 /// .send().await?;
338 /// println!("response {:?}", response);
339 /// Ok(())
340 /// }
341 /// ```
342 pub fn pause_queue(&self) -> super::builder::cloud_tasks::PauseQueue {
343 super::builder::cloud_tasks::PauseQueue::new(self.inner.clone())
344 }
345
346 /// Resume a queue.
347 ///
348 /// This method resumes a queue after it has been
349 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or
350 /// [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The state of a
351 /// queue is stored in the queue's [state][google.cloud.tasks.v2.Queue.state];
352 /// after calling this method it will be set to
353 /// [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING].
354 ///
355 /// WARNING: Resuming many high-QPS queues at the same time can
356 /// lead to target overloading. If you are resuming high-QPS
357 /// queues, follow the 500/50/5 pattern described in
358 /// [Managing Cloud Tasks Scaling
359 /// Risks](https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
360 ///
361 /// [google.cloud.tasks.v2.Queue.State.DISABLED]: crate::model::queue::State::Disabled
362 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
363 /// [google.cloud.tasks.v2.Queue.State.RUNNING]: crate::model::queue::State::Running
364 /// [google.cloud.tasks.v2.Queue.state]: crate::model::Queue::state
365 ///
366 /// # Example
367 /// ```
368 /// # use google_cloud_tasks_v2::client::CloudTasks;
369 /// use google_cloud_tasks_v2::Result;
370 /// async fn sample(
371 /// client: &CloudTasks
372 /// ) -> Result<()> {
373 /// let response = client.resume_queue()
374 /// /* set fields */
375 /// .send().await?;
376 /// println!("response {:?}", response);
377 /// Ok(())
378 /// }
379 /// ```
380 pub fn resume_queue(&self) -> super::builder::cloud_tasks::ResumeQueue {
381 super::builder::cloud_tasks::ResumeQueue::new(self.inner.clone())
382 }
383
384 /// Gets the access control policy for a [Queue][google.cloud.tasks.v2.Queue].
385 /// Returns an empty policy if the resource exists and does not have a policy
386 /// set.
387 ///
388 /// Authorization requires the following
389 /// [Google IAM](https://cloud.google.com/iam) permission on the specified
390 /// resource parent:
391 ///
392 /// * `cloudtasks.queues.getIamPolicy`
393 ///
394 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
395 ///
396 /// # Example
397 /// ```
398 /// # use google_cloud_tasks_v2::client::CloudTasks;
399 /// use google_cloud_tasks_v2::Result;
400 /// async fn sample(
401 /// client: &CloudTasks
402 /// ) -> Result<()> {
403 /// let response = client.get_iam_policy()
404 /// /* set fields */
405 /// .send().await?;
406 /// println!("response {:?}", response);
407 /// Ok(())
408 /// }
409 /// ```
410 pub fn get_iam_policy(&self) -> super::builder::cloud_tasks::GetIamPolicy {
411 super::builder::cloud_tasks::GetIamPolicy::new(self.inner.clone())
412 }
413
414 /// Sets the access control policy for a [Queue][google.cloud.tasks.v2.Queue].
415 /// Replaces any existing policy.
416 ///
417 /// Note: The Cloud Console does not check queue-level IAM permissions yet.
418 /// Project-level permissions are required to use the Cloud Console.
419 ///
420 /// Authorization requires the following
421 /// [Google IAM](https://cloud.google.com/iam) permission on the specified
422 /// resource parent:
423 ///
424 /// * `cloudtasks.queues.setIamPolicy`
425 ///
426 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
427 ///
428 /// # Example
429 /// ```
430 /// # use google_cloud_tasks_v2::client::CloudTasks;
431 /// use google_cloud_tasks_v2::Result;
432 /// async fn sample(
433 /// client: &CloudTasks
434 /// ) -> Result<()> {
435 /// let response = client.set_iam_policy()
436 /// /* set fields */
437 /// .send().await?;
438 /// println!("response {:?}", response);
439 /// Ok(())
440 /// }
441 /// ```
442 pub fn set_iam_policy(&self) -> super::builder::cloud_tasks::SetIamPolicy {
443 super::builder::cloud_tasks::SetIamPolicy::new(self.inner.clone())
444 }
445
446 /// Returns permissions that a caller has on a
447 /// [Queue][google.cloud.tasks.v2.Queue]. If the resource does not exist, this
448 /// will return an empty set of permissions, not a
449 /// [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.
450 ///
451 /// Note: This operation is designed to be used for building permission-aware
452 /// UIs and command-line tools, not for authorization checking. This operation
453 /// may "fail open" without warning.
454 ///
455 /// [google.cloud.tasks.v2.Queue]: crate::model::Queue
456 ///
457 /// # Example
458 /// ```
459 /// # use google_cloud_tasks_v2::client::CloudTasks;
460 /// use google_cloud_tasks_v2::Result;
461 /// async fn sample(
462 /// client: &CloudTasks
463 /// ) -> Result<()> {
464 /// let response = client.test_iam_permissions()
465 /// /* set fields */
466 /// .send().await?;
467 /// println!("response {:?}", response);
468 /// Ok(())
469 /// }
470 /// ```
471 pub fn test_iam_permissions(&self) -> super::builder::cloud_tasks::TestIamPermissions {
472 super::builder::cloud_tasks::TestIamPermissions::new(self.inner.clone())
473 }
474
475 /// Lists the tasks in a queue.
476 ///
477 /// By default, only the [BASIC][google.cloud.tasks.v2.Task.View.BASIC] view is
478 /// retrieved due to performance considerations;
479 /// [response_view][google.cloud.tasks.v2.ListTasksRequest.response_view]
480 /// controls the subset of information which is returned.
481 ///
482 /// The tasks may be returned in any order. The ordering may change at any
483 /// time.
484 ///
485 /// [google.cloud.tasks.v2.ListTasksRequest.response_view]: crate::model::ListTasksRequest::response_view
486 /// [google.cloud.tasks.v2.Task.View.BASIC]: crate::model::task::View::Basic
487 ///
488 /// # Example
489 /// ```
490 /// # use google_cloud_tasks_v2::client::CloudTasks;
491 /// use google_cloud_gax::paginator::ItemPaginator as _;
492 /// use google_cloud_tasks_v2::Result;
493 /// async fn sample(
494 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
495 /// ) -> Result<()> {
496 /// let mut list = client.list_tasks()
497 /// .set_parent(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
498 /// .by_item();
499 /// while let Some(item) = list.next().await.transpose()? {
500 /// println!("{:?}", item);
501 /// }
502 /// Ok(())
503 /// }
504 /// ```
505 pub fn list_tasks(&self) -> super::builder::cloud_tasks::ListTasks {
506 super::builder::cloud_tasks::ListTasks::new(self.inner.clone())
507 }
508
509 /// Gets a task.
510 ///
511 /// After a task is successfully executed or has exhausted its retry attempts,
512 /// the task is deleted. A `GetTask` request for a deleted task returns a
513 /// `NOT_FOUND` error.
514 ///
515 /// # Example
516 /// ```
517 /// # use google_cloud_tasks_v2::client::CloudTasks;
518 /// use google_cloud_tasks_v2::Result;
519 /// async fn sample(
520 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str, task_id: &str
521 /// ) -> Result<()> {
522 /// let response = client.get_task()
523 /// .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}/tasks/{task_id}"))
524 /// .send().await?;
525 /// println!("response {:?}", response);
526 /// Ok(())
527 /// }
528 /// ```
529 pub fn get_task(&self) -> super::builder::cloud_tasks::GetTask {
530 super::builder::cloud_tasks::GetTask::new(self.inner.clone())
531 }
532
533 /// Creates a task and adds it to a queue.
534 ///
535 /// Tasks cannot be updated after creation; there is no UpdateTask command.
536 ///
537 /// * The maximum task size is 100KB.
538 ///
539 /// # Example
540 /// ```
541 /// # use google_cloud_tasks_v2::client::CloudTasks;
542 /// use google_cloud_tasks_v2::model::Task;
543 /// use google_cloud_tasks_v2::Result;
544 /// async fn sample(
545 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str
546 /// ) -> Result<()> {
547 /// let response = client.create_task()
548 /// .set_parent(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}"))
549 /// .set_task(
550 /// Task::new()/* set fields */
551 /// )
552 /// .send().await?;
553 /// println!("response {:?}", response);
554 /// Ok(())
555 /// }
556 /// ```
557 pub fn create_task(&self) -> super::builder::cloud_tasks::CreateTask {
558 super::builder::cloud_tasks::CreateTask::new(self.inner.clone())
559 }
560
561 /// Creates a batch of tasks and adds them to a queue.
562 ///
563 /// All tasks must be for the same queue.
564 /// A maximum of 100 tasks can be created in a single batch.
565 ///
566 /// # Long running operations
567 ///
568 /// This method is used to start, and/or poll a [long-running Operation].
569 /// The [Working with long-running operations] chapter in the [user guide]
570 /// covers these operations in detail.
571 ///
572 /// [long-running operation]: https://google.aip.dev/151
573 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
574 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
575 ///
576 /// # Example
577 /// ```
578 /// # use google_cloud_tasks_v2::client::CloudTasks;
579 /// use google_cloud_lro::Poller;
580 /// use google_cloud_tasks_v2::Result;
581 /// async fn sample(
582 /// client: &CloudTasks
583 /// ) -> Result<()> {
584 /// let response = client.batch_create_tasks()
585 /// /* set fields */
586 /// .poller().until_done().await?;
587 /// println!("response {:?}", response);
588 /// Ok(())
589 /// }
590 /// ```
591 pub fn batch_create_tasks(&self) -> super::builder::cloud_tasks::BatchCreateTasks {
592 super::builder::cloud_tasks::BatchCreateTasks::new(self.inner.clone())
593 }
594
595 /// Deletes a task.
596 ///
597 /// A task can be deleted if it is scheduled or dispatched. A task
598 /// cannot be deleted if it has executed successfully or permanently
599 /// failed.
600 ///
601 /// # Example
602 /// ```
603 /// # use google_cloud_tasks_v2::client::CloudTasks;
604 /// use google_cloud_tasks_v2::Result;
605 /// async fn sample(
606 /// client: &CloudTasks, project_id: &str, location_id: &str, queue_id: &str, task_id: &str
607 /// ) -> Result<()> {
608 /// client.delete_task()
609 /// .set_name(format!("projects/{project_id}/locations/{location_id}/queues/{queue_id}/tasks/{task_id}"))
610 /// .send().await?;
611 /// Ok(())
612 /// }
613 /// ```
614 pub fn delete_task(&self) -> super::builder::cloud_tasks::DeleteTask {
615 super::builder::cloud_tasks::DeleteTask::new(self.inner.clone())
616 }
617
618 /// Deletes a batch of tasks.
619 /// This is a non-atomic operation: if deletion fails for some tasks, it
620 /// can still succeed for others. The metadata field of
621 /// google.longrunning.Operation contains details of failed deletions.
622 /// A maximum of 1000 tasks can be deleted in a batch.
623 ///
624 /// # Long running operations
625 ///
626 /// This method is used to start, and/or poll a [long-running Operation].
627 /// The [Working with long-running operations] chapter in the [user guide]
628 /// covers these operations in detail.
629 ///
630 /// [long-running operation]: https://google.aip.dev/151
631 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
632 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
633 ///
634 /// # Example
635 /// ```
636 /// # use google_cloud_tasks_v2::client::CloudTasks;
637 /// use google_cloud_lro::Poller;
638 /// use google_cloud_tasks_v2::Result;
639 /// async fn sample(
640 /// client: &CloudTasks
641 /// ) -> Result<()> {
642 /// client.batch_delete_tasks()
643 /// /* set fields */
644 /// .poller().until_done().await?;
645 /// Ok(())
646 /// }
647 /// ```
648 pub fn batch_delete_tasks(&self) -> super::builder::cloud_tasks::BatchDeleteTasks {
649 super::builder::cloud_tasks::BatchDeleteTasks::new(self.inner.clone())
650 }
651
652 /// Forces a task to run now.
653 ///
654 /// When this method is called, Cloud Tasks will dispatch the task, even if
655 /// the task is already running, the queue has reached its
656 /// [RateLimits][google.cloud.tasks.v2.RateLimits] or is
657 /// [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
658 ///
659 /// This command is meant to be used for manual debugging. For
660 /// example, [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] can be used to
661 /// retry a failed task after a fix has been made or to manually force a task
662 /// to be dispatched now.
663 ///
664 /// If Cloud Tasks receives a successful response from the task's
665 /// target, then the task will be deleted; otherwise the task's
666 /// [schedule_time][google.cloud.tasks.v2.Task.schedule_time] will be reset to
667 /// the time that [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] was
668 /// called plus the retry delay specified in the queue's
669 /// [RetryConfig][google.cloud.tasks.v2.RetryConfig].
670 ///
671 /// [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] returns
672 /// [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a
673 /// task that has already succeeded or permanently failed.
674 ///
675 /// [google.cloud.tasks.v2.CloudTasks.RunTask]: crate::client::CloudTasks::run_task
676 /// [google.cloud.tasks.v2.Queue.State.PAUSED]: crate::model::queue::State::Paused
677 /// [google.cloud.tasks.v2.RateLimits]: crate::model::RateLimits
678 /// [google.cloud.tasks.v2.RetryConfig]: crate::model::RetryConfig
679 /// [google.cloud.tasks.v2.Task.schedule_time]: crate::model::Task::schedule_time
680 ///
681 /// # Example
682 /// ```
683 /// # use google_cloud_tasks_v2::client::CloudTasks;
684 /// use google_cloud_tasks_v2::Result;
685 /// async fn sample(
686 /// client: &CloudTasks
687 /// ) -> Result<()> {
688 /// let response = client.run_task()
689 /// /* set fields */
690 /// .send().await?;
691 /// println!("response {:?}", response);
692 /// Ok(())
693 /// }
694 /// ```
695 pub fn run_task(&self) -> super::builder::cloud_tasks::RunTask {
696 super::builder::cloud_tasks::RunTask::new(self.inner.clone())
697 }
698
699 /// Creates or Updates a CMEK config.
700 ///
701 /// Updates the Customer Managed Encryption Key associated with the Cloud Tasks
702 /// location (Creates if the key does not already exist). All new tasks created
703 /// in the location will be encrypted at-rest with the KMS-key provided in the
704 /// config.
705 ///
706 /// # Example
707 /// ```
708 /// # use google_cloud_tasks_v2::client::CloudTasks;
709 /// # extern crate wkt as google_cloud_wkt;
710 /// use google_cloud_wkt::FieldMask;
711 /// use google_cloud_tasks_v2::model::CmekConfig;
712 /// use google_cloud_tasks_v2::Result;
713 /// async fn sample(
714 /// client: &CloudTasks, project_id: &str, location_id: &str
715 /// ) -> Result<()> {
716 /// let response = client.update_cmek_config()
717 /// .set_cmek_config(
718 /// CmekConfig::new().set_name(format!("projects/{project_id}/locations/{location_id}/cmekConfig"))/* set fields */
719 /// )
720 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
721 /// .send().await?;
722 /// println!("response {:?}", response);
723 /// Ok(())
724 /// }
725 /// ```
726 pub fn update_cmek_config(&self) -> super::builder::cloud_tasks::UpdateCmekConfig {
727 super::builder::cloud_tasks::UpdateCmekConfig::new(self.inner.clone())
728 }
729
730 /// Gets the CMEK config.
731 ///
732 /// Gets the Customer Managed Encryption Key configured with the Cloud Tasks
733 /// location. By default there is no kms_key configured.
734 ///
735 /// # Example
736 /// ```
737 /// # use google_cloud_tasks_v2::client::CloudTasks;
738 /// use google_cloud_tasks_v2::Result;
739 /// async fn sample(
740 /// client: &CloudTasks, project_id: &str, location_id: &str
741 /// ) -> Result<()> {
742 /// let response = client.get_cmek_config()
743 /// .set_name(format!("projects/{project_id}/locations/{location_id}/cmekConfig"))
744 /// .send().await?;
745 /// println!("response {:?}", response);
746 /// Ok(())
747 /// }
748 /// ```
749 pub fn get_cmek_config(&self) -> super::builder::cloud_tasks::GetCmekConfig {
750 super::builder::cloud_tasks::GetCmekConfig::new(self.inner.clone())
751 }
752
753 /// Lists information about the supported locations for this service.
754 ///
755 /// This method lists locations based on the resource scope provided in
756 /// the [ListLocationsRequest.name][google.cloud.location.ListLocationsRequest.name] field: *
757 /// **Global locations**: If `name` is empty, the method lists the
758 /// public locations available to all projects. * **Project-specific
759 /// locations**: If `name` follows the format
760 /// `projects/{project}`, the method lists locations visible to that
761 /// specific project. This includes public, private, or other
762 /// project-specific locations enabled for the project.
763 ///
764 /// For gRPC and client library implementations, the resource name is
765 /// passed as the `name` field. For direct service calls, the resource
766 /// name is
767 /// incorporated into the request path based on the specific service
768 /// implementation and version.
769 ///
770 /// [google.cloud.location.ListLocationsRequest.name]: google_cloud_location::model::ListLocationsRequest::name
771 ///
772 /// # Example
773 /// ```
774 /// # use google_cloud_tasks_v2::client::CloudTasks;
775 /// use google_cloud_gax::paginator::ItemPaginator as _;
776 /// use google_cloud_tasks_v2::Result;
777 /// async fn sample(
778 /// client: &CloudTasks
779 /// ) -> Result<()> {
780 /// let mut list = client.list_locations()
781 /// /* set fields */
782 /// .by_item();
783 /// while let Some(item) = list.next().await.transpose()? {
784 /// println!("{:?}", item);
785 /// }
786 /// Ok(())
787 /// }
788 /// ```
789 pub fn list_locations(&self) -> super::builder::cloud_tasks::ListLocations {
790 super::builder::cloud_tasks::ListLocations::new(self.inner.clone())
791 }
792
793 /// Gets information about a location.
794 ///
795 /// # Example
796 /// ```
797 /// # use google_cloud_tasks_v2::client::CloudTasks;
798 /// use google_cloud_tasks_v2::Result;
799 /// async fn sample(
800 /// client: &CloudTasks
801 /// ) -> Result<()> {
802 /// let response = client.get_location()
803 /// /* set fields */
804 /// .send().await?;
805 /// println!("response {:?}", response);
806 /// Ok(())
807 /// }
808 /// ```
809 pub fn get_location(&self) -> super::builder::cloud_tasks::GetLocation {
810 super::builder::cloud_tasks::GetLocation::new(self.inner.clone())
811 }
812
813 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
814 ///
815 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
816 ///
817 /// # Example
818 /// ```
819 /// # use google_cloud_tasks_v2::client::CloudTasks;
820 /// use google_cloud_tasks_v2::Result;
821 /// async fn sample(
822 /// client: &CloudTasks
823 /// ) -> Result<()> {
824 /// let response = client.get_operation()
825 /// /* set fields */
826 /// .send().await?;
827 /// println!("response {:?}", response);
828 /// Ok(())
829 /// }
830 /// ```
831 pub fn get_operation(&self) -> super::builder::cloud_tasks::GetOperation {
832 super::builder::cloud_tasks::GetOperation::new(self.inner.clone())
833 }
834}