Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py: 47%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

171 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 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# 

16import inspect 

17import json 

18import logging as std_logging 

19import pickle 

20from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union 

21import warnings 

22 

23from google.api_core import exceptions as core_exceptions 

24from google.api_core import gapic_v1, grpc_helpers_async 

25from google.api_core import retry_async as retries 

26from google.auth import credentials as ga_credentials # type: ignore 

27from google.auth.transport.grpc import SslCredentials # type: ignore 

28from google.cloud.location import locations_pb2 # type: ignore 

29from google.iam.v1 import iam_policy_pb2 # type: ignore 

30from google.iam.v1 import policy_pb2 # type: ignore 

31from google.protobuf import empty_pb2 # type: ignore 

32from google.protobuf.json_format import MessageToJson 

33import google.protobuf.message 

34import grpc # type: ignore 

35from grpc.experimental import aio # type: ignore 

36import proto # type: ignore 

37 

38from google.cloud.tasks_v2.types import cloudtasks 

39from google.cloud.tasks_v2.types import queue 

40from google.cloud.tasks_v2.types import queue as gct_queue 

41from google.cloud.tasks_v2.types import task 

42from google.cloud.tasks_v2.types import task as gct_task 

43 

44from .base import DEFAULT_CLIENT_INFO, CloudTasksTransport 

45from .grpc import CloudTasksGrpcTransport 

46 

47try: 

48 from google.api_core import client_logging # type: ignore 

49 

50 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

51except ImportError: # pragma: NO COVER 

52 CLIENT_LOGGING_SUPPORTED = False 

53 

54_LOGGER = std_logging.getLogger(__name__) 

55 

56 

57class _LoggingClientAIOInterceptor( 

58 grpc.aio.UnaryUnaryClientInterceptor 

59): # pragma: NO COVER 

60 async def intercept_unary_unary(self, continuation, client_call_details, request): 

61 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

62 std_logging.DEBUG 

63 ) 

64 if logging_enabled: # pragma: NO COVER 

65 request_metadata = client_call_details.metadata 

66 if isinstance(request, proto.Message): 

67 request_payload = type(request).to_json(request) 

68 elif isinstance(request, google.protobuf.message.Message): 

69 request_payload = MessageToJson(request) 

70 else: 

71 request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" 

72 

73 request_metadata = { 

74 key: value.decode("utf-8") if isinstance(value, bytes) else value 

75 for key, value in request_metadata 

76 } 

77 grpc_request = { 

78 "payload": request_payload, 

79 "requestMethod": "grpc", 

80 "metadata": dict(request_metadata), 

81 } 

82 _LOGGER.debug( 

83 f"Sending request for {client_call_details.method}", 

84 extra={ 

85 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

86 "rpcName": str(client_call_details.method), 

87 "request": grpc_request, 

88 "metadata": grpc_request["metadata"], 

89 }, 

90 ) 

91 response = await continuation(client_call_details, request) 

92 if logging_enabled: # pragma: NO COVER 

93 response_metadata = await response.trailing_metadata() 

94 # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples 

95 metadata = ( 

96 dict([(k, str(v)) for k, v in response_metadata]) 

97 if response_metadata 

98 else None 

99 ) 

100 result = await response 

101 if isinstance(result, proto.Message): 

102 response_payload = type(result).to_json(result) 

103 elif isinstance(result, google.protobuf.message.Message): 

104 response_payload = MessageToJson(result) 

105 else: 

106 response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" 

107 grpc_response = { 

108 "payload": response_payload, 

109 "metadata": metadata, 

110 "status": "OK", 

111 } 

112 _LOGGER.debug( 

113 f"Received response to rpc {client_call_details.method}.", 

114 extra={ 

115 "serviceName": "google.cloud.tasks.v2.CloudTasks", 

116 "rpcName": str(client_call_details.method), 

117 "response": grpc_response, 

118 "metadata": grpc_response["metadata"], 

119 }, 

120 ) 

121 return response 

122 

123 

124class CloudTasksGrpcAsyncIOTransport(CloudTasksTransport): 

125 """gRPC AsyncIO backend transport for CloudTasks. 

126 

127 Cloud Tasks allows developers to manage the execution of 

128 background work in their applications. 

129 

130 This class defines the same methods as the primary client, so the 

131 primary client can load the underlying transport implementation 

132 and call it. 

133 

134 It sends protocol buffers over the wire using gRPC (which is built on 

135 top of HTTP/2); the ``grpcio`` package must be installed. 

136 """ 

137 

138 _grpc_channel: aio.Channel 

139 _stubs: Dict[str, Callable] = {} 

140 

141 @classmethod 

142 def create_channel( 

143 cls, 

144 host: str = "cloudtasks.googleapis.com", 

145 credentials: Optional[ga_credentials.Credentials] = None, 

146 credentials_file: Optional[str] = None, 

147 scopes: Optional[Sequence[str]] = None, 

148 quota_project_id: Optional[str] = None, 

149 **kwargs, 

150 ) -> aio.Channel: 

151 """Create and return a gRPC AsyncIO channel object. 

152 Args: 

153 host (Optional[str]): The host for the channel to use. 

154 credentials (Optional[~.Credentials]): The 

155 authorization credentials to attach to requests. These 

156 credentials identify this application to the service. If 

157 none are specified, the client will attempt to ascertain 

158 the credentials from the environment. 

159 credentials_file (Optional[str]): Deprecated. A file with credentials that can 

160 be loaded with :func:`google.auth.load_credentials_from_file`. This argument will be 

161 removed in the next major version of this library. 

162 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

163 service. These are only used when credentials are not specified and 

164 are passed to :func:`google.auth.default`. 

165 quota_project_id (Optional[str]): An optional project to use for billing 

166 and quota. 

167 kwargs (Optional[dict]): Keyword arguments, which are passed to the 

168 channel creation. 

169 Returns: 

170 aio.Channel: A gRPC AsyncIO channel object. 

171 """ 

172 

173 return grpc_helpers_async.create_channel( 

174 host, 

175 credentials=credentials, 

176 credentials_file=credentials_file, 

177 quota_project_id=quota_project_id, 

178 default_scopes=cls.AUTH_SCOPES, 

179 scopes=scopes, 

180 default_host=cls.DEFAULT_HOST, 

181 **kwargs, 

182 ) 

183 

184 def __init__( 

185 self, 

186 *, 

187 host: str = "cloudtasks.googleapis.com", 

188 credentials: Optional[ga_credentials.Credentials] = None, 

189 credentials_file: Optional[str] = None, 

190 scopes: Optional[Sequence[str]] = None, 

191 channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, 

192 api_mtls_endpoint: Optional[str] = None, 

193 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

194 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, 

195 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

196 quota_project_id: Optional[str] = None, 

197 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

198 always_use_jwt_access: Optional[bool] = False, 

199 api_audience: Optional[str] = None, 

200 ) -> None: 

201 """Instantiate the transport. 

202 

203 Args: 

204 host (Optional[str]): 

205 The hostname to connect to (default: 'cloudtasks.googleapis.com'). 

206 credentials (Optional[google.auth.credentials.Credentials]): The 

207 authorization credentials to attach to requests. These 

208 credentials identify the application to the service; if none 

209 are specified, the client will attempt to ascertain the 

210 credentials from the environment. 

211 This argument is ignored if a ``channel`` instance is provided. 

212 credentials_file (Optional[str]): Deprecated. A file with credentials that can 

213 be loaded with :func:`google.auth.load_credentials_from_file`. 

214 This argument is ignored if a ``channel`` instance is provided. 

215 This argument will be removed in the next major version of this library. 

216 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

217 service. These are only used when credentials are not specified and 

218 are passed to :func:`google.auth.default`. 

219 channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): 

220 A ``Channel`` instance through which to make calls, or a Callable 

221 that constructs and returns one. If set to None, ``self.create_channel`` 

222 is used to create the channel. If a Callable is given, it will be called 

223 with the same arguments as used in ``self.create_channel``. 

224 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. 

225 If provided, it overrides the ``host`` argument and tries to create 

226 a mutual TLS channel with client SSL credentials from 

227 ``client_cert_source`` or application default SSL credentials. 

228 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): 

229 Deprecated. A callback to provide client SSL certificate bytes and 

230 private key bytes, both in PEM format. It is ignored if 

231 ``api_mtls_endpoint`` is None. 

232 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

233 for the grpc channel. It is ignored if a ``channel`` instance is provided. 

234 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): 

235 A callback to provide client certificate bytes and private key bytes, 

236 both in PEM format. It is used to configure a mutual TLS channel. It is 

237 ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. 

238 quota_project_id (Optional[str]): An optional project to use for billing 

239 and quota. 

240 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

241 The client info used to send a user-agent string along with 

242 API requests. If ``None``, then default info will be used. 

243 Generally, you only need to set this if you're developing 

244 your own client library. 

245 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

246 be used for service account credentials. 

247 

248 Raises: 

249 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

250 creation failed for any reason. 

251 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

252 and ``credentials_file`` are passed. 

253 """ 

254 self._grpc_channel = None 

255 self._ssl_channel_credentials = ssl_channel_credentials 

256 self._stubs: Dict[str, Callable] = {} 

257 

258 if api_mtls_endpoint: 

259 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 

260 if client_cert_source: 

261 warnings.warn("client_cert_source is deprecated", DeprecationWarning) 

262 

263 if isinstance(channel, aio.Channel): 

264 # Ignore credentials if a channel was passed. 

265 credentials = None 

266 self._ignore_credentials = True 

267 # If a channel was explicitly provided, set it. 

268 self._grpc_channel = channel 

269 self._ssl_channel_credentials = None 

270 else: 

271 if api_mtls_endpoint: 

272 host = api_mtls_endpoint 

273 

274 # Create SSL credentials with client_cert_source or application 

275 # default SSL credentials. 

276 if client_cert_source: 

277 cert, key = client_cert_source() 

278 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

279 certificate_chain=cert, private_key=key 

280 ) 

281 else: 

282 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

283 

284 else: 

285 if client_cert_source_for_mtls and not ssl_channel_credentials: 

286 cert, key = client_cert_source_for_mtls() 

287 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

288 certificate_chain=cert, private_key=key 

289 ) 

290 

291 # The base transport sets the host, credentials and scopes 

292 super().__init__( 

293 host=host, 

294 credentials=credentials, 

295 credentials_file=credentials_file, 

296 scopes=scopes, 

297 quota_project_id=quota_project_id, 

298 client_info=client_info, 

299 always_use_jwt_access=always_use_jwt_access, 

300 api_audience=api_audience, 

301 ) 

302 

303 if not self._grpc_channel: 

304 # initialize with the provided callable or the default channel 

305 channel_init = channel or type(self).create_channel 

306 self._grpc_channel = channel_init( 

307 self._host, 

308 # use the credentials which are saved 

309 credentials=self._credentials, 

310 # Set ``credentials_file`` to ``None`` here as 

311 # the credentials that we saved earlier should be used. 

312 credentials_file=None, 

313 scopes=self._scopes, 

314 ssl_credentials=self._ssl_channel_credentials, 

315 quota_project_id=quota_project_id, 

316 options=[ 

317 ("grpc.max_send_message_length", -1), 

318 ("grpc.max_receive_message_length", -1), 

319 ], 

320 ) 

321 

322 self._interceptor = _LoggingClientAIOInterceptor() 

323 self._grpc_channel._unary_unary_interceptors.append(self._interceptor) 

324 self._logged_channel = self._grpc_channel 

325 self._wrap_with_kind = ( 

326 "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters 

327 ) 

328 # Wrap messages. This must be done after self._logged_channel exists 

329 self._prep_wrapped_messages(client_info) 

330 

331 @property 

332 def grpc_channel(self) -> aio.Channel: 

333 """Create the channel designed to connect to this service. 

334 

335 This property caches on the instance; repeated calls return 

336 the same channel. 

337 """ 

338 # Return the channel from cache. 

339 return self._grpc_channel 

340 

341 @property 

342 def list_queues( 

343 self, 

344 ) -> Callable[ 

345 [cloudtasks.ListQueuesRequest], Awaitable[cloudtasks.ListQueuesResponse] 

346 ]: 

347 r"""Return a callable for the list queues method over gRPC. 

348 

349 Lists queues. 

350 

351 Queues are returned in lexicographical order. 

352 

353 Returns: 

354 Callable[[~.ListQueuesRequest], 

355 Awaitable[~.ListQueuesResponse]]: 

356 A function that, when called, will call the underlying RPC 

357 on the server. 

358 """ 

359 # Generate a "stub function" on-the-fly which will actually make 

360 # the request. 

361 # gRPC handles serialization and deserialization, so we just need 

362 # to pass in the functions for each. 

363 if "list_queues" not in self._stubs: 

364 self._stubs["list_queues"] = self._logged_channel.unary_unary( 

365 "/google.cloud.tasks.v2.CloudTasks/ListQueues", 

366 request_serializer=cloudtasks.ListQueuesRequest.serialize, 

367 response_deserializer=cloudtasks.ListQueuesResponse.deserialize, 

368 ) 

369 return self._stubs["list_queues"] 

370 

371 @property 

372 def get_queue( 

373 self, 

374 ) -> Callable[[cloudtasks.GetQueueRequest], Awaitable[queue.Queue]]: 

375 r"""Return a callable for the get queue method over gRPC. 

376 

377 Gets a queue. 

378 

379 Returns: 

380 Callable[[~.GetQueueRequest], 

381 Awaitable[~.Queue]]: 

382 A function that, when called, will call the underlying RPC 

383 on the server. 

384 """ 

385 # Generate a "stub function" on-the-fly which will actually make 

386 # the request. 

387 # gRPC handles serialization and deserialization, so we just need 

388 # to pass in the functions for each. 

389 if "get_queue" not in self._stubs: 

390 self._stubs["get_queue"] = self._logged_channel.unary_unary( 

391 "/google.cloud.tasks.v2.CloudTasks/GetQueue", 

392 request_serializer=cloudtasks.GetQueueRequest.serialize, 

393 response_deserializer=queue.Queue.deserialize, 

394 ) 

395 return self._stubs["get_queue"] 

396 

397 @property 

398 def create_queue( 

399 self, 

400 ) -> Callable[[cloudtasks.CreateQueueRequest], Awaitable[gct_queue.Queue]]: 

401 r"""Return a callable for the create queue method over gRPC. 

402 

403 Creates a queue. 

404 

405 Queues created with this method allow tasks to live for a 

406 maximum of 31 days. After a task is 31 days old, the task will 

407 be deleted regardless of whether it was dispatched or not. 

408 

409 WARNING: Using this method may have unintended side effects if 

410 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file 

411 to manage your queues. Read `Overview of Queue Management and 

412 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__ 

413 before using this method. 

414 

415 Returns: 

416 Callable[[~.CreateQueueRequest], 

417 Awaitable[~.Queue]]: 

418 A function that, when called, will call the underlying RPC 

419 on the server. 

420 """ 

421 # Generate a "stub function" on-the-fly which will actually make 

422 # the request. 

423 # gRPC handles serialization and deserialization, so we just need 

424 # to pass in the functions for each. 

425 if "create_queue" not in self._stubs: 

426 self._stubs["create_queue"] = self._logged_channel.unary_unary( 

427 "/google.cloud.tasks.v2.CloudTasks/CreateQueue", 

428 request_serializer=cloudtasks.CreateQueueRequest.serialize, 

429 response_deserializer=gct_queue.Queue.deserialize, 

430 ) 

431 return self._stubs["create_queue"] 

432 

433 @property 

434 def update_queue( 

435 self, 

436 ) -> Callable[[cloudtasks.UpdateQueueRequest], Awaitable[gct_queue.Queue]]: 

437 r"""Return a callable for the update queue method over gRPC. 

438 

439 Updates a queue. 

440 

441 This method creates the queue if it does not exist and updates 

442 the queue if it does exist. 

443 

444 Queues created with this method allow tasks to live for a 

445 maximum of 31 days. After a task is 31 days old, the task will 

446 be deleted regardless of whether it was dispatched or not. 

447 

448 WARNING: Using this method may have unintended side effects if 

449 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file 

450 to manage your queues. Read `Overview of Queue Management and 

451 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__ 

452 before using this method. 

453 

454 Returns: 

455 Callable[[~.UpdateQueueRequest], 

456 Awaitable[~.Queue]]: 

457 A function that, when called, will call the underlying RPC 

458 on the server. 

459 """ 

460 # Generate a "stub function" on-the-fly which will actually make 

461 # the request. 

462 # gRPC handles serialization and deserialization, so we just need 

463 # to pass in the functions for each. 

464 if "update_queue" not in self._stubs: 

465 self._stubs["update_queue"] = self._logged_channel.unary_unary( 

466 "/google.cloud.tasks.v2.CloudTasks/UpdateQueue", 

467 request_serializer=cloudtasks.UpdateQueueRequest.serialize, 

468 response_deserializer=gct_queue.Queue.deserialize, 

469 ) 

470 return self._stubs["update_queue"] 

471 

472 @property 

473 def delete_queue( 

474 self, 

475 ) -> Callable[[cloudtasks.DeleteQueueRequest], Awaitable[empty_pb2.Empty]]: 

476 r"""Return a callable for the delete queue method over gRPC. 

477 

478 Deletes a queue. 

479 

480 This command will delete the queue even if it has tasks in it. 

481 

482 Note: If you delete a queue, a queue with the same name can't be 

483 created for 7 days. 

484 

485 WARNING: Using this method may have unintended side effects if 

486 you are using an App Engine ``queue.yaml`` or ``queue.xml`` file 

487 to manage your queues. Read `Overview of Queue Management and 

488 queue.yaml <https://cloud.google.com/tasks/docs/queue-yaml>`__ 

489 before using this method. 

490 

491 Returns: 

492 Callable[[~.DeleteQueueRequest], 

493 Awaitable[~.Empty]]: 

494 A function that, when called, will call the underlying RPC 

495 on the server. 

496 """ 

497 # Generate a "stub function" on-the-fly which will actually make 

498 # the request. 

499 # gRPC handles serialization and deserialization, so we just need 

500 # to pass in the functions for each. 

501 if "delete_queue" not in self._stubs: 

502 self._stubs["delete_queue"] = self._logged_channel.unary_unary( 

503 "/google.cloud.tasks.v2.CloudTasks/DeleteQueue", 

504 request_serializer=cloudtasks.DeleteQueueRequest.serialize, 

505 response_deserializer=empty_pb2.Empty.FromString, 

506 ) 

507 return self._stubs["delete_queue"] 

508 

509 @property 

510 def purge_queue( 

511 self, 

512 ) -> Callable[[cloudtasks.PurgeQueueRequest], Awaitable[queue.Queue]]: 

513 r"""Return a callable for the purge queue method over gRPC. 

514 

515 Purges a queue by deleting all of its tasks. 

516 

517 All tasks created before this method is called are 

518 permanently deleted. 

519 

520 Purge operations can take up to one minute to take 

521 effect. Tasks might be dispatched before the purge takes 

522 effect. A purge is irreversible. 

523 

524 Returns: 

525 Callable[[~.PurgeQueueRequest], 

526 Awaitable[~.Queue]]: 

527 A function that, when called, will call the underlying RPC 

528 on the server. 

529 """ 

530 # Generate a "stub function" on-the-fly which will actually make 

531 # the request. 

532 # gRPC handles serialization and deserialization, so we just need 

533 # to pass in the functions for each. 

534 if "purge_queue" not in self._stubs: 

535 self._stubs["purge_queue"] = self._logged_channel.unary_unary( 

536 "/google.cloud.tasks.v2.CloudTasks/PurgeQueue", 

537 request_serializer=cloudtasks.PurgeQueueRequest.serialize, 

538 response_deserializer=queue.Queue.deserialize, 

539 ) 

540 return self._stubs["purge_queue"] 

541 

542 @property 

543 def pause_queue( 

544 self, 

545 ) -> Callable[[cloudtasks.PauseQueueRequest], Awaitable[queue.Queue]]: 

546 r"""Return a callable for the pause queue method over gRPC. 

547 

548 Pauses the queue. 

549 

550 If a queue is paused then the system will stop dispatching tasks 

551 until the queue is resumed via 

552 [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. 

553 Tasks can still be added when the queue is paused. A queue is 

554 paused if its [state][google.cloud.tasks.v2.Queue.state] is 

555 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. 

556 

557 Returns: 

558 Callable[[~.PauseQueueRequest], 

559 Awaitable[~.Queue]]: 

560 A function that, when called, will call the underlying RPC 

561 on the server. 

562 """ 

563 # Generate a "stub function" on-the-fly which will actually make 

564 # the request. 

565 # gRPC handles serialization and deserialization, so we just need 

566 # to pass in the functions for each. 

567 if "pause_queue" not in self._stubs: 

568 self._stubs["pause_queue"] = self._logged_channel.unary_unary( 

569 "/google.cloud.tasks.v2.CloudTasks/PauseQueue", 

570 request_serializer=cloudtasks.PauseQueueRequest.serialize, 

571 response_deserializer=queue.Queue.deserialize, 

572 ) 

573 return self._stubs["pause_queue"] 

574 

575 @property 

576 def resume_queue( 

577 self, 

578 ) -> Callable[[cloudtasks.ResumeQueueRequest], Awaitable[queue.Queue]]: 

579 r"""Return a callable for the resume queue method over gRPC. 

580 

581 Resume a queue. 

582 

583 This method resumes a queue after it has been 

584 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED] or 

585 [DISABLED][google.cloud.tasks.v2.Queue.State.DISABLED]. The 

586 state of a queue is stored in the queue's 

587 [state][google.cloud.tasks.v2.Queue.state]; after calling this 

588 method it will be set to 

589 [RUNNING][google.cloud.tasks.v2.Queue.State.RUNNING]. 

590 

591 WARNING: Resuming many high-QPS queues at the same time can lead 

592 to target overloading. If you are resuming high-QPS queues, 

593 follow the 500/50/5 pattern described in `Managing Cloud Tasks 

594 Scaling 

595 Risks <https://cloud.google.com/tasks/docs/manage-cloud-task-scaling>`__. 

596 

597 Returns: 

598 Callable[[~.ResumeQueueRequest], 

599 Awaitable[~.Queue]]: 

600 A function that, when called, will call the underlying RPC 

601 on the server. 

602 """ 

603 # Generate a "stub function" on-the-fly which will actually make 

604 # the request. 

605 # gRPC handles serialization and deserialization, so we just need 

606 # to pass in the functions for each. 

607 if "resume_queue" not in self._stubs: 

608 self._stubs["resume_queue"] = self._logged_channel.unary_unary( 

609 "/google.cloud.tasks.v2.CloudTasks/ResumeQueue", 

610 request_serializer=cloudtasks.ResumeQueueRequest.serialize, 

611 response_deserializer=queue.Queue.deserialize, 

612 ) 

613 return self._stubs["resume_queue"] 

614 

615 @property 

616 def get_iam_policy( 

617 self, 

618 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: 

619 r"""Return a callable for the get iam policy method over gRPC. 

620 

621 Gets the access control policy for a 

622 [Queue][google.cloud.tasks.v2.Queue]. Returns an empty policy if 

623 the resource exists and does not have a policy set. 

624 

625 Authorization requires the following `Google 

626 IAM <https://cloud.google.com/iam>`__ permission on the 

627 specified resource parent: 

628 

629 - ``cloudtasks.queues.getIamPolicy`` 

630 

631 Returns: 

632 Callable[[~.GetIamPolicyRequest], 

633 Awaitable[~.Policy]]: 

634 A function that, when called, will call the underlying RPC 

635 on the server. 

636 """ 

637 # Generate a "stub function" on-the-fly which will actually make 

638 # the request. 

639 # gRPC handles serialization and deserialization, so we just need 

640 # to pass in the functions for each. 

641 if "get_iam_policy" not in self._stubs: 

642 self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( 

643 "/google.cloud.tasks.v2.CloudTasks/GetIamPolicy", 

644 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

645 response_deserializer=policy_pb2.Policy.FromString, 

646 ) 

647 return self._stubs["get_iam_policy"] 

648 

649 @property 

650 def set_iam_policy( 

651 self, 

652 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], Awaitable[policy_pb2.Policy]]: 

653 r"""Return a callable for the set iam policy method over gRPC. 

654 

655 Sets the access control policy for a 

656 [Queue][google.cloud.tasks.v2.Queue]. Replaces any existing 

657 policy. 

658 

659 Note: The Cloud Console does not check queue-level IAM 

660 permissions yet. Project-level permissions are required to use 

661 the Cloud Console. 

662 

663 Authorization requires the following `Google 

664 IAM <https://cloud.google.com/iam>`__ permission on the 

665 specified resource parent: 

666 

667 - ``cloudtasks.queues.setIamPolicy`` 

668 

669 Returns: 

670 Callable[[~.SetIamPolicyRequest], 

671 Awaitable[~.Policy]]: 

672 A function that, when called, will call the underlying RPC 

673 on the server. 

674 """ 

675 # Generate a "stub function" on-the-fly which will actually make 

676 # the request. 

677 # gRPC handles serialization and deserialization, so we just need 

678 # to pass in the functions for each. 

679 if "set_iam_policy" not in self._stubs: 

680 self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( 

681 "/google.cloud.tasks.v2.CloudTasks/SetIamPolicy", 

682 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

683 response_deserializer=policy_pb2.Policy.FromString, 

684 ) 

685 return self._stubs["set_iam_policy"] 

686 

687 @property 

688 def test_iam_permissions( 

689 self, 

690 ) -> Callable[ 

691 [iam_policy_pb2.TestIamPermissionsRequest], 

692 Awaitable[iam_policy_pb2.TestIamPermissionsResponse], 

693 ]: 

694 r"""Return a callable for the test iam permissions method over gRPC. 

695 

696 Returns permissions that a caller has on a 

697 [Queue][google.cloud.tasks.v2.Queue]. If the resource does not 

698 exist, this will return an empty set of permissions, not a 

699 [NOT_FOUND][google.rpc.Code.NOT_FOUND] error. 

700 

701 Note: This operation is designed to be used for building 

702 permission-aware UIs and command-line tools, not for 

703 authorization checking. This operation may "fail open" without 

704 warning. 

705 

706 Returns: 

707 Callable[[~.TestIamPermissionsRequest], 

708 Awaitable[~.TestIamPermissionsResponse]]: 

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 "test_iam_permissions" not in self._stubs: 

717 self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( 

718 "/google.cloud.tasks.v2.CloudTasks/TestIamPermissions", 

719 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

720 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

721 ) 

722 return self._stubs["test_iam_permissions"] 

723 

724 @property 

725 def list_tasks( 

726 self, 

727 ) -> Callable[ 

728 [cloudtasks.ListTasksRequest], Awaitable[cloudtasks.ListTasksResponse] 

729 ]: 

730 r"""Return a callable for the list tasks method over gRPC. 

731 

732 Lists the tasks in a queue. 

733 

734 By default, only the 

735 [BASIC][google.cloud.tasks.v2.Task.View.BASIC] view is retrieved 

736 due to performance considerations; 

737 [response_view][google.cloud.tasks.v2.ListTasksRequest.response_view] 

738 controls the subset of information which is returned. 

739 

740 The tasks may be returned in any order. The ordering may change 

741 at any time. 

742 

743 Returns: 

744 Callable[[~.ListTasksRequest], 

745 Awaitable[~.ListTasksResponse]]: 

746 A function that, when called, will call the underlying RPC 

747 on the server. 

748 """ 

749 # Generate a "stub function" on-the-fly which will actually make 

750 # the request. 

751 # gRPC handles serialization and deserialization, so we just need 

752 # to pass in the functions for each. 

753 if "list_tasks" not in self._stubs: 

754 self._stubs["list_tasks"] = self._logged_channel.unary_unary( 

755 "/google.cloud.tasks.v2.CloudTasks/ListTasks", 

756 request_serializer=cloudtasks.ListTasksRequest.serialize, 

757 response_deserializer=cloudtasks.ListTasksResponse.deserialize, 

758 ) 

759 return self._stubs["list_tasks"] 

760 

761 @property 

762 def get_task(self) -> Callable[[cloudtasks.GetTaskRequest], Awaitable[task.Task]]: 

763 r"""Return a callable for the get task method over gRPC. 

764 

765 Gets a task. 

766 

767 Returns: 

768 Callable[[~.GetTaskRequest], 

769 Awaitable[~.Task]]: 

770 A function that, when called, will call the underlying RPC 

771 on the server. 

772 """ 

773 # Generate a "stub function" on-the-fly which will actually make 

774 # the request. 

775 # gRPC handles serialization and deserialization, so we just need 

776 # to pass in the functions for each. 

777 if "get_task" not in self._stubs: 

778 self._stubs["get_task"] = self._logged_channel.unary_unary( 

779 "/google.cloud.tasks.v2.CloudTasks/GetTask", 

780 request_serializer=cloudtasks.GetTaskRequest.serialize, 

781 response_deserializer=task.Task.deserialize, 

782 ) 

783 return self._stubs["get_task"] 

784 

785 @property 

786 def create_task( 

787 self, 

788 ) -> Callable[[cloudtasks.CreateTaskRequest], Awaitable[gct_task.Task]]: 

789 r"""Return a callable for the create task method over gRPC. 

790 

791 Creates a task and adds it to a queue. 

792 

793 Tasks cannot be updated after creation; there is no UpdateTask 

794 command. 

795 

796 - The maximum task size is 100KB. 

797 

798 Returns: 

799 Callable[[~.CreateTaskRequest], 

800 Awaitable[~.Task]]: 

801 A function that, when called, will call the underlying RPC 

802 on the server. 

803 """ 

804 # Generate a "stub function" on-the-fly which will actually make 

805 # the request. 

806 # gRPC handles serialization and deserialization, so we just need 

807 # to pass in the functions for each. 

808 if "create_task" not in self._stubs: 

809 self._stubs["create_task"] = self._logged_channel.unary_unary( 

810 "/google.cloud.tasks.v2.CloudTasks/CreateTask", 

811 request_serializer=cloudtasks.CreateTaskRequest.serialize, 

812 response_deserializer=gct_task.Task.deserialize, 

813 ) 

814 return self._stubs["create_task"] 

815 

816 @property 

817 def delete_task( 

818 self, 

819 ) -> Callable[[cloudtasks.DeleteTaskRequest], Awaitable[empty_pb2.Empty]]: 

820 r"""Return a callable for the delete task method over gRPC. 

821 

822 Deletes a task. 

823 

824 A task can be deleted if it is scheduled or dispatched. 

825 A task cannot be deleted if it has executed successfully 

826 or permanently failed. 

827 

828 Returns: 

829 Callable[[~.DeleteTaskRequest], 

830 Awaitable[~.Empty]]: 

831 A function that, when called, will call the underlying RPC 

832 on the server. 

833 """ 

834 # Generate a "stub function" on-the-fly which will actually make 

835 # the request. 

836 # gRPC handles serialization and deserialization, so we just need 

837 # to pass in the functions for each. 

838 if "delete_task" not in self._stubs: 

839 self._stubs["delete_task"] = self._logged_channel.unary_unary( 

840 "/google.cloud.tasks.v2.CloudTasks/DeleteTask", 

841 request_serializer=cloudtasks.DeleteTaskRequest.serialize, 

842 response_deserializer=empty_pb2.Empty.FromString, 

843 ) 

844 return self._stubs["delete_task"] 

845 

846 @property 

847 def run_task(self) -> Callable[[cloudtasks.RunTaskRequest], Awaitable[task.Task]]: 

848 r"""Return a callable for the run task method over gRPC. 

849 

850 Forces a task to run now. 

851 

852 When this method is called, Cloud Tasks will dispatch the task, 

853 even if the task is already running, the queue has reached its 

854 [RateLimits][google.cloud.tasks.v2.RateLimits] or is 

855 [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. 

856 

857 This command is meant to be used for manual debugging. For 

858 example, [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] can 

859 be used to retry a failed task after a fix has been made or to 

860 manually force a task to be dispatched now. 

861 

862 The dispatched task is returned. That is, the task that is 

863 returned contains the [status][Task.status] after the task is 

864 dispatched but before the task is received by its target. 

865 

866 If Cloud Tasks receives a successful response from the task's 

867 target, then the task will be deleted; otherwise the task's 

868 [schedule_time][google.cloud.tasks.v2.Task.schedule_time] will 

869 be reset to the time that 

870 [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] was called 

871 plus the retry delay specified in the queue's 

872 [RetryConfig][google.cloud.tasks.v2.RetryConfig]. 

873 

874 [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask] returns 

875 [NOT_FOUND][google.rpc.Code.NOT_FOUND] when it is called on a 

876 task that has already succeeded or permanently failed. 

877 

878 Returns: 

879 Callable[[~.RunTaskRequest], 

880 Awaitable[~.Task]]: 

881 A function that, when called, will call the underlying RPC 

882 on the server. 

883 """ 

884 # Generate a "stub function" on-the-fly which will actually make 

885 # the request. 

886 # gRPC handles serialization and deserialization, so we just need 

887 # to pass in the functions for each. 

888 if "run_task" not in self._stubs: 

889 self._stubs["run_task"] = self._logged_channel.unary_unary( 

890 "/google.cloud.tasks.v2.CloudTasks/RunTask", 

891 request_serializer=cloudtasks.RunTaskRequest.serialize, 

892 response_deserializer=task.Task.deserialize, 

893 ) 

894 return self._stubs["run_task"] 

895 

896 def _prep_wrapped_messages(self, client_info): 

897 """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" 

898 self._wrapped_methods = { 

899 self.list_queues: self._wrap_method( 

900 self.list_queues, 

901 default_retry=retries.AsyncRetry( 

902 initial=0.1, 

903 maximum=10.0, 

904 multiplier=1.3, 

905 predicate=retries.if_exception_type( 

906 core_exceptions.DeadlineExceeded, 

907 core_exceptions.ServiceUnavailable, 

908 ), 

909 deadline=20.0, 

910 ), 

911 default_timeout=20.0, 

912 client_info=client_info, 

913 ), 

914 self.get_queue: self._wrap_method( 

915 self.get_queue, 

916 default_retry=retries.AsyncRetry( 

917 initial=0.1, 

918 maximum=10.0, 

919 multiplier=1.3, 

920 predicate=retries.if_exception_type( 

921 core_exceptions.DeadlineExceeded, 

922 core_exceptions.ServiceUnavailable, 

923 ), 

924 deadline=20.0, 

925 ), 

926 default_timeout=20.0, 

927 client_info=client_info, 

928 ), 

929 self.create_queue: self._wrap_method( 

930 self.create_queue, 

931 default_timeout=20.0, 

932 client_info=client_info, 

933 ), 

934 self.update_queue: self._wrap_method( 

935 self.update_queue, 

936 default_timeout=20.0, 

937 client_info=client_info, 

938 ), 

939 self.delete_queue: self._wrap_method( 

940 self.delete_queue, 

941 default_retry=retries.AsyncRetry( 

942 initial=0.1, 

943 maximum=10.0, 

944 multiplier=1.3, 

945 predicate=retries.if_exception_type( 

946 core_exceptions.DeadlineExceeded, 

947 core_exceptions.ServiceUnavailable, 

948 ), 

949 deadline=20.0, 

950 ), 

951 default_timeout=20.0, 

952 client_info=client_info, 

953 ), 

954 self.purge_queue: self._wrap_method( 

955 self.purge_queue, 

956 default_timeout=20.0, 

957 client_info=client_info, 

958 ), 

959 self.pause_queue: self._wrap_method( 

960 self.pause_queue, 

961 default_timeout=20.0, 

962 client_info=client_info, 

963 ), 

964 self.resume_queue: self._wrap_method( 

965 self.resume_queue, 

966 default_timeout=20.0, 

967 client_info=client_info, 

968 ), 

969 self.get_iam_policy: self._wrap_method( 

970 self.get_iam_policy, 

971 default_retry=retries.AsyncRetry( 

972 initial=0.1, 

973 maximum=10.0, 

974 multiplier=1.3, 

975 predicate=retries.if_exception_type( 

976 core_exceptions.DeadlineExceeded, 

977 core_exceptions.ServiceUnavailable, 

978 ), 

979 deadline=20.0, 

980 ), 

981 default_timeout=20.0, 

982 client_info=client_info, 

983 ), 

984 self.set_iam_policy: self._wrap_method( 

985 self.set_iam_policy, 

986 default_timeout=20.0, 

987 client_info=client_info, 

988 ), 

989 self.test_iam_permissions: self._wrap_method( 

990 self.test_iam_permissions, 

991 default_retry=retries.AsyncRetry( 

992 initial=0.1, 

993 maximum=10.0, 

994 multiplier=1.3, 

995 predicate=retries.if_exception_type( 

996 core_exceptions.DeadlineExceeded, 

997 core_exceptions.ServiceUnavailable, 

998 ), 

999 deadline=20.0, 

1000 ), 

1001 default_timeout=20.0, 

1002 client_info=client_info, 

1003 ), 

1004 self.list_tasks: self._wrap_method( 

1005 self.list_tasks, 

1006 default_retry=retries.AsyncRetry( 

1007 initial=0.1, 

1008 maximum=10.0, 

1009 multiplier=1.3, 

1010 predicate=retries.if_exception_type( 

1011 core_exceptions.DeadlineExceeded, 

1012 core_exceptions.ServiceUnavailable, 

1013 ), 

1014 deadline=20.0, 

1015 ), 

1016 default_timeout=20.0, 

1017 client_info=client_info, 

1018 ), 

1019 self.get_task: self._wrap_method( 

1020 self.get_task, 

1021 default_retry=retries.AsyncRetry( 

1022 initial=0.1, 

1023 maximum=10.0, 

1024 multiplier=1.3, 

1025 predicate=retries.if_exception_type( 

1026 core_exceptions.DeadlineExceeded, 

1027 core_exceptions.ServiceUnavailable, 

1028 ), 

1029 deadline=20.0, 

1030 ), 

1031 default_timeout=20.0, 

1032 client_info=client_info, 

1033 ), 

1034 self.create_task: self._wrap_method( 

1035 self.create_task, 

1036 default_timeout=20.0, 

1037 client_info=client_info, 

1038 ), 

1039 self.delete_task: self._wrap_method( 

1040 self.delete_task, 

1041 default_retry=retries.AsyncRetry( 

1042 initial=0.1, 

1043 maximum=10.0, 

1044 multiplier=1.3, 

1045 predicate=retries.if_exception_type( 

1046 core_exceptions.DeadlineExceeded, 

1047 core_exceptions.ServiceUnavailable, 

1048 ), 

1049 deadline=20.0, 

1050 ), 

1051 default_timeout=20.0, 

1052 client_info=client_info, 

1053 ), 

1054 self.run_task: self._wrap_method( 

1055 self.run_task, 

1056 default_timeout=20.0, 

1057 client_info=client_info, 

1058 ), 

1059 self.get_location: self._wrap_method( 

1060 self.get_location, 

1061 default_timeout=None, 

1062 client_info=client_info, 

1063 ), 

1064 self.list_locations: self._wrap_method( 

1065 self.list_locations, 

1066 default_timeout=None, 

1067 client_info=client_info, 

1068 ), 

1069 } 

1070 

1071 def _wrap_method(self, func, *args, **kwargs): 

1072 if self._wrap_with_kind: # pragma: NO COVER 

1073 kwargs["kind"] = self.kind 

1074 return gapic_v1.method_async.wrap_method(func, *args, **kwargs) 

1075 

1076 def close(self): 

1077 return self._logged_channel.close() 

1078 

1079 @property 

1080 def kind(self) -> str: 

1081 return "grpc_asyncio" 

1082 

1083 @property 

1084 def list_locations( 

1085 self, 

1086 ) -> Callable[ 

1087 [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse 

1088 ]: 

1089 r"""Return a callable for the list locations method over gRPC.""" 

1090 # Generate a "stub function" on-the-fly which will actually make 

1091 # the request. 

1092 # gRPC handles serialization and deserialization, so we just need 

1093 # to pass in the functions for each. 

1094 if "list_locations" not in self._stubs: 

1095 self._stubs["list_locations"] = self._logged_channel.unary_unary( 

1096 "/google.cloud.location.Locations/ListLocations", 

1097 request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, 

1098 response_deserializer=locations_pb2.ListLocationsResponse.FromString, 

1099 ) 

1100 return self._stubs["list_locations"] 

1101 

1102 @property 

1103 def get_location( 

1104 self, 

1105 ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: 

1106 r"""Return a callable for the list locations method over gRPC.""" 

1107 # Generate a "stub function" on-the-fly which will actually make 

1108 # the request. 

1109 # gRPC handles serialization and deserialization, so we just need 

1110 # to pass in the functions for each. 

1111 if "get_location" not in self._stubs: 

1112 self._stubs["get_location"] = self._logged_channel.unary_unary( 

1113 "/google.cloud.location.Locations/GetLocation", 

1114 request_serializer=locations_pb2.GetLocationRequest.SerializeToString, 

1115 response_deserializer=locations_pb2.Location.FromString, 

1116 ) 

1117 return self._stubs["get_location"] 

1118 

1119 

1120__all__ = ("CloudTasksGrpcAsyncIOTransport",)