Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py: 90%
135 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:07 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:07 +0000
1# -*- coding: utf-8 -*-
2# Copyright 2022 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16from typing import Callable, Dict, Optional, Sequence, Tuple, Union
17import warnings
19from google.api_core import gapic_v1, grpc_helpers
20import google.auth # type: ignore
21from google.auth import credentials as ga_credentials # type: ignore
22from google.auth.transport.grpc import SslCredentials # type: ignore
23from google.iam.v1 import iam_policy_pb2 # type: ignore
24from google.iam.v1 import policy_pb2 # type: ignore
25from google.protobuf import empty_pb2 # type: ignore
26import grpc # type: ignore
28from google.cloud.tasks_v2.types import cloudtasks
29from google.cloud.tasks_v2.types import queue
30from google.cloud.tasks_v2.types import queue as gct_queue
31from google.cloud.tasks_v2.types import task
32from google.cloud.tasks_v2.types import task as gct_task
34from .base import DEFAULT_CLIENT_INFO, CloudTasksTransport
37class CloudTasksGrpcTransport(CloudTasksTransport):
38 """gRPC backend transport for CloudTasks.
40 Cloud Tasks allows developers to manage the execution of
41 background work in their applications.
43 This class defines the same methods as the primary client, so the
44 primary client can load the underlying transport implementation
45 and call it.
47 It sends protocol buffers over the wire using gRPC (which is built on
48 top of HTTP/2); the ``grpcio`` package must be installed.
49 """
51 _stubs: Dict[str, Callable]
53 def __init__(
54 self,
55 *,
56 host: str = "cloudtasks.googleapis.com",
57 credentials: Optional[ga_credentials.Credentials] = None,
58 credentials_file: Optional[str] = None,
59 scopes: Optional[Sequence[str]] = None,
60 channel: Optional[grpc.Channel] = None,
61 api_mtls_endpoint: Optional[str] = None,
62 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
63 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
64 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
65 quota_project_id: Optional[str] = None,
66 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
67 always_use_jwt_access: Optional[bool] = False,
68 api_audience: Optional[str] = None,
69 ) -> None:
70 """Instantiate the transport.
72 Args:
73 host (Optional[str]):
74 The hostname to connect to.
75 credentials (Optional[google.auth.credentials.Credentials]): The
76 authorization credentials to attach to requests. These
77 credentials identify the application to the service; if none
78 are specified, the client will attempt to ascertain the
79 credentials from the environment.
80 This argument is ignored if ``channel`` is provided.
81 credentials_file (Optional[str]): A file with credentials that can
82 be loaded with :func:`google.auth.load_credentials_from_file`.
83 This argument is ignored if ``channel`` is provided.
84 scopes (Optional(Sequence[str])): A list of scopes. This argument is
85 ignored if ``channel`` is provided.
86 channel (Optional[grpc.Channel]): A ``Channel`` instance through
87 which to make calls.
88 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
89 If provided, it overrides the ``host`` argument and tries to create
90 a mutual TLS channel with client SSL credentials from
91 ``client_cert_source`` or application default SSL credentials.
92 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
93 Deprecated. A callback to provide client SSL certificate bytes and
94 private key bytes, both in PEM format. It is ignored if
95 ``api_mtls_endpoint`` is None.
96 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
97 for the grpc channel. It is ignored if ``channel`` is provided.
98 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
99 A callback to provide client certificate bytes and private key bytes,
100 both in PEM format. It is used to configure a mutual TLS channel. It is
101 ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
102 quota_project_id (Optional[str]): An optional project to use for billing
103 and quota.
104 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
105 The client info used to send a user-agent string along with
106 API requests. If ``None``, then default info will be used.
107 Generally, you only need to set this if you're developing
108 your own client library.
109 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
110 be used for service account credentials.
112 Raises:
113 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
114 creation failed for any reason.
115 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
116 and ``credentials_file`` are passed.
117 """
118 self._grpc_channel = None
119 self._ssl_channel_credentials = ssl_channel_credentials
120 self._stubs: Dict[str, Callable] = {}
122 if api_mtls_endpoint:
123 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
124 if client_cert_source:
125 warnings.warn("client_cert_source is deprecated", DeprecationWarning)
127 if channel:
128 # Ignore credentials if a channel was passed.
129 credentials = False
130 # If a channel was explicitly provided, set it.
131 self._grpc_channel = channel
132 self._ssl_channel_credentials = None
134 else:
135 if api_mtls_endpoint:
136 host = api_mtls_endpoint
138 # Create SSL credentials with client_cert_source or application
139 # default SSL credentials.
140 if client_cert_source:
141 cert, key = client_cert_source()
142 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
143 certificate_chain=cert, private_key=key
144 )
145 else:
146 self._ssl_channel_credentials = SslCredentials().ssl_credentials
148 else:
149 if client_cert_source_for_mtls and not ssl_channel_credentials:
150 cert, key = client_cert_source_for_mtls()
151 self._ssl_channel_credentials = grpc.ssl_channel_credentials(
152 certificate_chain=cert, private_key=key
153 )
155 # The base transport sets the host, credentials and scopes
156 super().__init__(
157 host=host,
158 credentials=credentials,
159 credentials_file=credentials_file,
160 scopes=scopes,
161 quota_project_id=quota_project_id,
162 client_info=client_info,
163 always_use_jwt_access=always_use_jwt_access,
164 api_audience=api_audience,
165 )
167 if not self._grpc_channel:
168 self._grpc_channel = type(self).create_channel(
169 self._host,
170 # use the credentials which are saved
171 credentials=self._credentials,
172 # Set ``credentials_file`` to ``None`` here as
173 # the credentials that we saved earlier should be used.
174 credentials_file=None,
175 scopes=self._scopes,
176 ssl_credentials=self._ssl_channel_credentials,
177 quota_project_id=quota_project_id,
178 options=[
179 ("grpc.max_send_message_length", -1),
180 ("grpc.max_receive_message_length", -1),
181 ],
182 )
184 # Wrap messages. This must be done after self._grpc_channel exists
185 self._prep_wrapped_messages(client_info)
187 @classmethod
188 def create_channel(
189 cls,
190 host: str = "cloudtasks.googleapis.com",
191 credentials: Optional[ga_credentials.Credentials] = None,
192 credentials_file: Optional[str] = None,
193 scopes: Optional[Sequence[str]] = None,
194 quota_project_id: Optional[str] = None,
195 **kwargs,
196 ) -> grpc.Channel:
197 """Create and return a gRPC channel object.
198 Args:
199 host (Optional[str]): The host for the channel to use.
200 credentials (Optional[~.Credentials]): The
201 authorization credentials to attach to requests. These
202 credentials identify this application to the service. If
203 none are specified, the client will attempt to ascertain
204 the credentials from the environment.
205 credentials_file (Optional[str]): A file with credentials that can
206 be loaded with :func:`google.auth.load_credentials_from_file`.
207 This argument is mutually exclusive with credentials.
208 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
209 service. These are only used when credentials are not specified and
210 are passed to :func:`google.auth.default`.
211 quota_project_id (Optional[str]): An optional project to use for billing
212 and quota.
213 kwargs (Optional[dict]): Keyword arguments, which are passed to the
214 channel creation.
215 Returns:
216 grpc.Channel: A gRPC channel object.
218 Raises:
219 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
220 and ``credentials_file`` are passed.
221 """
223 return grpc_helpers.create_channel(
224 host,
225 credentials=credentials,
226 credentials_file=credentials_file,
227 quota_project_id=quota_project_id,
228 default_scopes=cls.AUTH_SCOPES,
229 scopes=scopes,
230 default_host=cls.DEFAULT_HOST,
231 **kwargs,
232 )
234 @property
235 def grpc_channel(self) -> grpc.Channel:
236 """Return the channel designed to connect to this service."""
237 return self._grpc_channel
239 @property
240 def list_queues(
241 self,
242 ) -> Callable[[cloudtasks.ListQueuesRequest], cloudtasks.ListQueuesResponse]:
243 r"""Return a callable for the list queues method over gRPC.
245 Lists queues.
246 Queues are returned in lexicographical order.
248 Returns:
249 Callable[[~.ListQueuesRequest],
250 ~.ListQueuesResponse]:
251 A function that, when called, will call the underlying RPC
252 on the server.
253 """
254 # Generate a "stub function" on-the-fly which will actually make
255 # the request.
256 # gRPC handles serialization and deserialization, so we just need
257 # to pass in the functions for each.
258 if "list_queues" not in self._stubs:
259 self._stubs["list_queues"] = self.grpc_channel.unary_unary(
260 "/google.cloud.tasks.v2.CloudTasks/ListQueues",
261 request_serializer=cloudtasks.ListQueuesRequest.serialize,
262 response_deserializer=cloudtasks.ListQueuesResponse.deserialize,
263 )
264 return self._stubs["list_queues"]
266 @property
267 def get_queue(self) -> Callable[[cloudtasks.GetQueueRequest], queue.Queue]:
268 r"""Return a callable for the get queue method over gRPC.
270 Gets a queue.
272 Returns:
273 Callable[[~.GetQueueRequest],
274 ~.Queue]:
275 A function that, when called, will call the underlying RPC
276 on the server.
277 """
278 # Generate a "stub function" on-the-fly which will actually make
279 # the request.
280 # gRPC handles serialization and deserialization, so we just need
281 # to pass in the functions for each.
282 if "get_queue" not in self._stubs:
283 self._stubs["get_queue"] = self.grpc_channel.unary_unary(
284 "/google.cloud.tasks.v2.CloudTasks/GetQueue",
285 request_serializer=cloudtasks.GetQueueRequest.serialize,
286 response_deserializer=queue.Queue.deserialize,
287 )
288 return self._stubs["get_queue"]
290 @property
291 def create_queue(
292 self,
293 ) -> Callable[[cloudtasks.CreateQueueRequest], gct_queue.Queue]:
294 r"""Return a callable for the create queue method over gRPC.
296 Creates a queue.
298 Queues created with this method allow tasks to live for a
299 maximum of 31 days. After a task is 31 days old, the task will
300 be deleted regardless of whether it was dispatched or not.
302 WARNING: Using this method may have unintended side effects if
303 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file
304 to manage your queues. Read `Overview of Queue Management and
305 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__
306 before using this method.
308 Returns:
309 Callable[[~.CreateQueueRequest],
310 ~.Queue]:
311 A function that, when called, will call the underlying RPC
312 on the server.
313 """
314 # Generate a "stub function" on-the-fly which will actually make
315 # the request.
316 # gRPC handles serialization and deserialization, so we just need
317 # to pass in the functions for each.
318 if "create_queue" not in self._stubs:
319 self._stubs["create_queue"] = self.grpc_channel.unary_unary(
320 "/google.cloud.tasks.v2.CloudTasks/CreateQueue",
321 request_serializer=cloudtasks.CreateQueueRequest.serialize,
322 response_deserializer=gct_queue.Queue.deserialize,
323 )
324 return self._stubs["create_queue"]
326 @property
327 def update_queue(
328 self,
329 ) -> Callable[[cloudtasks.UpdateQueueRequest], gct_queue.Queue]:
330 r"""Return a callable for the update queue method over gRPC.
332 Updates a queue.
334 This method creates the queue if it does not exist and updates
335 the queue if it does exist.
337 Queues created with this method allow tasks to live for a
338 maximum of 31 days. After a task is 31 days old, the task will
339 be deleted regardless of whether it was dispatched or not.
341 WARNING: Using this method may have unintended side effects if
342 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file
343 to manage your queues. Read `Overview of Queue Management and
344 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__
345 before using this method.
347 Returns:
348 Callable[[~.UpdateQueueRequest],
349 ~.Queue]:
350 A function that, when called, will call the underlying RPC
351 on the server.
352 """
353 # Generate a "stub function" on-the-fly which will actually make
354 # the request.
355 # gRPC handles serialization and deserialization, so we just need
356 # to pass in the functions for each.
357 if "update_queue" not in self._stubs:
358 self._stubs["update_queue"] = self.grpc_channel.unary_unary(
359 "/google.cloud.tasks.v2.CloudTasks/UpdateQueue",
360 request_serializer=cloudtasks.UpdateQueueRequest.serialize,
361 response_deserializer=gct_queue.Queue.deserialize,
362 )
363 return self._stubs["update_queue"]
365 @property
366 def delete_queue(
367 self,
368 ) -> Callable[[cloudtasks.DeleteQueueRequest], empty_pb2.Empty]:
369 r"""Return a callable for the delete queue method over gRPC.
371 Deletes a queue.
373 This command will delete the queue even if it has tasks in it.
375 Note: If you delete a queue, a queue with the same name can't be
376 created for 7 days.
378 WARNING: Using this method may have unintended side effects if
379 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file
380 to manage your queues. Read `Overview of Queue Management and
381 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__
382 before using this method.
384 Returns:
385 Callable[[~.DeleteQueueRequest],
386 ~.Empty]:
387 A function that, when called, will call the underlying RPC
388 on the server.
389 """
390 # Generate a "stub function" on-the-fly which will actually make
391 # the request.
392 # gRPC handles serialization and deserialization, so we just need
393 # to pass in the functions for each.
394 if "delete_queue" not in self._stubs:
395 self._stubs["delete_queue"] = self.grpc_channel.unary_unary(
396 "/google.cloud.tasks.v2.CloudTasks/DeleteQueue",
397 request_serializer=cloudtasks.DeleteQueueRequest.serialize,
398 response_deserializer=empty_pb2.Empty.FromString,
399 )
400 return self._stubs["delete_queue"]
402 @property
403 def purge_queue(self) -> Callable[[cloudtasks.PurgeQueueRequest], queue.Queue]:
404 r"""Return a callable for the purge queue method over gRPC.
406 Purges a queue by deleting all of its tasks.
407 All tasks created before this method is called are
408 permanently deleted.
409 Purge operations can take up to one minute to take
410 effect. Tasks might be dispatched before the purge takes
411 effect. A purge is irreversible.
413 Returns:
414 Callable[[~.PurgeQueueRequest],
415 ~.Queue]:
416 A function that, when called, will call the underlying RPC
417 on the server.
418 """
419 # Generate a "stub function" on-the-fly which will actually make
420 # the request.
421 # gRPC handles serialization and deserialization, so we just need
422 # to pass in the functions for each.
423 if "purge_queue" not in self._stubs:
424 self._stubs["purge_queue"] = self.grpc_channel.unary_unary(
425 "/google.cloud.tasks.v2.CloudTasks/PurgeQueue",
426 request_serializer=cloudtasks.PurgeQueueRequest.serialize,
427 response_deserializer=queue.Queue.deserialize,
428 )
429 return self._stubs["purge_queue"]
431 @property
432 def pause_queue(self) -> Callable[[cloudtasks.PauseQueueRequest], queue.Queue]:
433 r"""Return a callable for the pause queue method over gRPC.
435 Pauses the queue.
437 If a queue is paused then the system will stop dispatching tasks
438 until the queue is resumed via
439 [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue].
440 Tasks can still be added when the queue is paused. A queue is
441 paused if its [state][google.cloud.tasks.v2.Queue.state] is
442 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
444 Returns:
445 Callable[[~.PauseQueueRequest],
446 ~.Queue]:
447 A function that, when called, will call the underlying RPC
448 on the server.
449 """
450 # Generate a "stub function" on-the-fly which will actually make
451 # the request.
452 # gRPC handles serialization and deserialization, so we just need
453 # to pass in the functions for each.
454 if "pause_queue" not in self._stubs:
455 self._stubs["pause_queue"] = self.grpc_channel.unary_unary(
456 "/google.cloud.tasks.v2.CloudTasks/PauseQueue",
457 request_serializer=cloudtasks.PauseQueueRequest.serialize,
458 response_deserializer=queue.Queue.deserialize,
459 )
460 return self._stubs["pause_queue"]
462 @property
463 def resume_queue(self) -> Callable[[cloudtasks.ResumeQueueRequest], queue.Queue]:
464 r"""Return a callable for the resume queue method over gRPC.
466 Resume a queue.
468 This method resumes a queue after it has been
469 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or
470 [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The
471 state of a queue is stored in the queue's
472 [state][google.cloud.tasks.v2.Queue.state]; after calling this
473 method it will be set to
474 [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING].
476 WARNING: Resuming many high-QPS queues at the same time can lead
477 to target overloading. If you are resuming high-QPS queues,
478 follow the 500/50/5 pattern described in `Managing Cloud Tasks
479 Scaling
480 Risks <https://cloud.google.com/tasks/docs/manage-cloud-task-scaling>`__.
482 Returns:
483 Callable[[~.ResumeQueueRequest],
484 ~.Queue]:
485 A function that, when called, will call the underlying RPC
486 on the server.
487 """
488 # Generate a "stub function" on-the-fly which will actually make
489 # the request.
490 # gRPC handles serialization and deserialization, so we just need
491 # to pass in the functions for each.
492 if "resume_queue" not in self._stubs:
493 self._stubs["resume_queue"] = self.grpc_channel.unary_unary(
494 "/google.cloud.tasks.v2.CloudTasks/ResumeQueue",
495 request_serializer=cloudtasks.ResumeQueueRequest.serialize,
496 response_deserializer=queue.Queue.deserialize,
497 )
498 return self._stubs["resume_queue"]
500 @property
501 def get_iam_policy(
502 self,
503 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
504 r"""Return a callable for the get iam policy method over gRPC.
506 Gets the access control policy for a
507 [Queue][google.cloud.tasks.v2.Queue]. Returns an empty policy if
508 the resource exists and does not have a policy set.
510 Authorization requires the following `Google
511 IAM <https://cloud.google.com/iam>`__ permission on the
512 specified resource parent:
514 - ``cloudtasks.queues.getIamPolicy``
516 Returns:
517 Callable[[~.GetIamPolicyRequest],
518 ~.Policy]:
519 A function that, when called, will call the underlying RPC
520 on the server.
521 """
522 # Generate a "stub function" on-the-fly which will actually make
523 # the request.
524 # gRPC handles serialization and deserialization, so we just need
525 # to pass in the functions for each.
526 if "get_iam_policy" not in self._stubs:
527 self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary(
528 "/google.cloud.tasks.v2.CloudTasks/GetIamPolicy",
529 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString,
530 response_deserializer=policy_pb2.Policy.FromString,
531 )
532 return self._stubs["get_iam_policy"]
534 @property
535 def set_iam_policy(
536 self,
537 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
538 r"""Return a callable for the set iam policy method over gRPC.
540 Sets the access control policy for a
541 [Queue][google.cloud.tasks.v2.Queue]. Replaces any existing
542 policy.
544 Note: The Cloud Console does not check queue-level IAM
545 permissions yet. Project-level permissions are required to use
546 the Cloud Console.
548 Authorization requires the following `Google
549 IAM <https://cloud.google.com/iam>`__ permission on the
550 specified resource parent:
552 - ``cloudtasks.queues.setIamPolicy``
554 Returns:
555 Callable[[~.SetIamPolicyRequest],
556 ~.Policy]:
557 A function that, when called, will call the underlying RPC
558 on the server.
559 """
560 # Generate a "stub function" on-the-fly which will actually make
561 # the request.
562 # gRPC handles serialization and deserialization, so we just need
563 # to pass in the functions for each.
564 if "set_iam_policy" not in self._stubs:
565 self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary(
566 "/google.cloud.tasks.v2.CloudTasks/SetIamPolicy",
567 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString,
568 response_deserializer=policy_pb2.Policy.FromString,
569 )
570 return self._stubs["set_iam_policy"]
572 @property
573 def test_iam_permissions(
574 self,
575 ) -> Callable[
576 [iam_policy_pb2.TestIamPermissionsRequest],
577 iam_policy_pb2.TestIamPermissionsResponse,
578 ]:
579 r"""Return a callable for the test iam permissions method over gRPC.
581 Returns permissions that a caller has on a
582 [Queue][google.cloud.tasks.v2.Queue]. If the resource does not
583 exist, this will return an empty set of permissions, not a
584 [NOT_FOUND][google.rpc.Code.NOT_FOUND] error.
586 Note: This operation is designed to be used for building
587 permission-aware UIs and command-line tools, not for
588 authorization checking. This operation may "fail open" without
589 warning.
591 Returns:
592 Callable[[~.TestIamPermissionsRequest],
593 ~.TestIamPermissionsResponse]:
594 A function that, when called, will call the underlying RPC
595 on the server.
596 """
597 # Generate a "stub function" on-the-fly which will actually make
598 # the request.
599 # gRPC handles serialization and deserialization, so we just need
600 # to pass in the functions for each.
601 if "test_iam_permissions" not in self._stubs:
602 self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary(
603 "/google.cloud.tasks.v2.CloudTasks/TestIamPermissions",
604 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString,
605 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString,
606 )
607 return self._stubs["test_iam_permissions"]
609 @property
610 def list_tasks(
611 self,
612 ) -> Callable[[cloudtasks.ListTasksRequest], cloudtasks.ListTasksResponse]:
613 r"""Return a callable for the list tasks method over gRPC.
615 Lists the tasks in a queue.
617 By default, only the
618 [BASIC][google.cloud.tasks.v2.Task.View.BASIC] view is retrieved
619 due to performance considerations;
620 [response_view][google.cloud.tasks.v2.ListTasksRequest.response_view]
621 controls the subset of information which is returned.
623 The tasks may be returned in any order. The ordering may change
624 at any time.
626 Returns:
627 Callable[[~.ListTasksRequest],
628 ~.ListTasksResponse]:
629 A function that, when called, will call the underlying RPC
630 on the server.
631 """
632 # Generate a "stub function" on-the-fly which will actually make
633 # the request.
634 # gRPC handles serialization and deserialization, so we just need
635 # to pass in the functions for each.
636 if "list_tasks" not in self._stubs:
637 self._stubs["list_tasks"] = self.grpc_channel.unary_unary(
638 "/google.cloud.tasks.v2.CloudTasks/ListTasks",
639 request_serializer=cloudtasks.ListTasksRequest.serialize,
640 response_deserializer=cloudtasks.ListTasksResponse.deserialize,
641 )
642 return self._stubs["list_tasks"]
644 @property
645 def get_task(self) -> Callable[[cloudtasks.GetTaskRequest], task.Task]:
646 r"""Return a callable for the get task method over gRPC.
648 Gets a task.
650 Returns:
651 Callable[[~.GetTaskRequest],
652 ~.Task]:
653 A function that, when called, will call the underlying RPC
654 on the server.
655 """
656 # Generate a "stub function" on-the-fly which will actually make
657 # the request.
658 # gRPC handles serialization and deserialization, so we just need
659 # to pass in the functions for each.
660 if "get_task" not in self._stubs:
661 self._stubs["get_task"] = self.grpc_channel.unary_unary(
662 "/google.cloud.tasks.v2.CloudTasks/GetTask",
663 request_serializer=cloudtasks.GetTaskRequest.serialize,
664 response_deserializer=task.Task.deserialize,
665 )
666 return self._stubs["get_task"]
668 @property
669 def create_task(self) -> Callable[[cloudtasks.CreateTaskRequest], gct_task.Task]:
670 r"""Return a callable for the create task method over gRPC.
672 Creates a task and adds it to a queue.
674 Tasks cannot be updated after creation; there is no UpdateTask
675 command.
677 - The maximum task size is 100KB.
679 Returns:
680 Callable[[~.CreateTaskRequest],
681 ~.Task]:
682 A function that, when called, will call the underlying RPC
683 on the server.
684 """
685 # Generate a "stub function" on-the-fly which will actually make
686 # the request.
687 # gRPC handles serialization and deserialization, so we just need
688 # to pass in the functions for each.
689 if "create_task" not in self._stubs:
690 self._stubs["create_task"] = self.grpc_channel.unary_unary(
691 "/google.cloud.tasks.v2.CloudTasks/CreateTask",
692 request_serializer=cloudtasks.CreateTaskRequest.serialize,
693 response_deserializer=gct_task.Task.deserialize,
694 )
695 return self._stubs["create_task"]
697 @property
698 def delete_task(self) -> Callable[[cloudtasks.DeleteTaskRequest], empty_pb2.Empty]:
699 r"""Return a callable for the delete task method over gRPC.
701 Deletes a task.
702 A task can be deleted if it is scheduled or dispatched.
703 A task cannot be deleted if it has executed successfully
704 or permanently failed.
706 Returns:
707 Callable[[~.DeleteTaskRequest],
708 ~.Empty]:
709 A function that, when called, will call the underlying RPC
710 on the server.
711 """
712 # Generate a "stub function" on-the-fly which will actually make
713 # the request.
714 # gRPC handles serialization and deserialization, so we just need
715 # to pass in the functions for each.
716 if "delete_task" not in self._stubs:
717 self._stubs["delete_task"] = self.grpc_channel.unary_unary(
718 "/google.cloud.tasks.v2.CloudTasks/DeleteTask",
719 request_serializer=cloudtasks.DeleteTaskRequest.serialize,
720 response_deserializer=empty_pb2.Empty.FromString,
721 )
722 return self._stubs["delete_task"]
724 @property
725 def run_task(self) -> Callable[[cloudtasks.RunTaskRequest], task.Task]:
726 r"""Return a callable for the run task method over gRPC.
728 Forces a task to run now.
730 When this method is called, Cloud Tasks will dispatch the task,
731 even if the task is already running, the queue has reached its
732 [RateLimits][google.cloud.tasks.v2.RateLimits] or is
733 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED].
735 This command is meant to be used for manual debugging. For
736 example, [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] can
737 be used to retry a failed task after a fix has been made or to
738 manually force a task to be dispatched now.
740 The dispatched task is returned. That is, the task that is
741 returned contains the [status][Task.status] after the task is
742 dispatched but before the task is received by its target.
744 If Cloud Tasks receives a successful response from the task's
745 target, then the task will be deleted; otherwise the task's
746 [schedule_time][google.cloud.tasks.v2.Task.schedule_time] will
747 be reset to the time that
748 [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] was called
749 plus the retry delay specified in the queue's
750 [RetryConfig][google.cloud.tasks.v2.RetryConfig].
752 [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] returns
753 [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a
754 task that has already succeeded or permanently failed.
756 Returns:
757 Callable[[~.RunTaskRequest],
758 ~.Task]:
759 A function that, when called, will call the underlying RPC
760 on the server.
761 """
762 # Generate a "stub function" on-the-fly which will actually make
763 # the request.
764 # gRPC handles serialization and deserialization, so we just need
765 # to pass in the functions for each.
766 if "run_task" not in self._stubs:
767 self._stubs["run_task"] = self.grpc_channel.unary_unary(
768 "/google.cloud.tasks.v2.CloudTasks/RunTask",
769 request_serializer=cloudtasks.RunTaskRequest.serialize,
770 response_deserializer=task.Task.deserialize,
771 )
772 return self._stubs["run_task"]
774 def close(self):
775 self.grpc_channel.close()
777 @property
778 def kind(self) -> str:
779 return "grpc"
782__all__ = ("CloudTasksGrpcTransport",)