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

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

160 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 json 

17import logging as std_logging 

18import pickle 

19from typing import Callable, Dict, Optional, Sequence, Tuple, Union 

20import warnings 

21 

22from google.api_core import gapic_v1, grpc_helpers 

23import google.auth # type: ignore 

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

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

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

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

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

29from google.protobuf import empty_pb2 # type: ignore 

30from google.protobuf.json_format import MessageToJson 

31import google.protobuf.message 

32import grpc # type: ignore 

33import proto # type: ignore 

34 

35from google.cloud.tasks_v2.types import cloudtasks 

36from google.cloud.tasks_v2.types import queue 

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

38from google.cloud.tasks_v2.types import task 

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

40 

41from .base import DEFAULT_CLIENT_INFO, CloudTasksTransport 

42 

43try: 

44 from google.api_core import client_logging # type: ignore 

45 

46 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

47except ImportError: # pragma: NO COVER 

48 CLIENT_LOGGING_SUPPORTED = False 

49 

50_LOGGER = std_logging.getLogger(__name__) 

51 

52 

53class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER 

54 def intercept_unary_unary(self, continuation, client_call_details, request): 

55 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

56 std_logging.DEBUG 

57 ) 

58 if logging_enabled: # pragma: NO COVER 

59 request_metadata = client_call_details.metadata 

60 if isinstance(request, proto.Message): 

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

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

63 request_payload = MessageToJson(request) 

64 else: 

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

66 

67 request_metadata = { 

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

69 for key, value in request_metadata 

70 } 

71 grpc_request = { 

72 "payload": request_payload, 

73 "requestMethod": "grpc", 

74 "metadata": dict(request_metadata), 

75 } 

76 _LOGGER.debug( 

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

78 extra={ 

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

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

81 "request": grpc_request, 

82 "metadata": grpc_request["metadata"], 

83 }, 

84 ) 

85 response = continuation(client_call_details, request) 

86 if logging_enabled: # pragma: NO COVER 

87 response_metadata = response.trailing_metadata() 

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

89 metadata = ( 

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

91 if response_metadata 

92 else None 

93 ) 

94 result = response.result() 

95 if isinstance(result, proto.Message): 

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

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

98 response_payload = MessageToJson(result) 

99 else: 

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

101 grpc_response = { 

102 "payload": response_payload, 

103 "metadata": metadata, 

104 "status": "OK", 

105 } 

106 _LOGGER.debug( 

107 f"Received response for {client_call_details.method}.", 

108 extra={ 

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

110 "rpcName": client_call_details.method, 

111 "response": grpc_response, 

112 "metadata": grpc_response["metadata"], 

113 }, 

114 ) 

115 return response 

116 

117 

118class CloudTasksGrpcTransport(CloudTasksTransport): 

119 """gRPC backend transport for CloudTasks. 

120 

121 Cloud Tasks allows developers to manage the execution of 

122 background work in their applications. 

123 

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

125 primary client can load the underlying transport implementation 

126 and call it. 

127 

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

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

130 """ 

131 

132 _stubs: Dict[str, Callable] 

133 

134 def __init__( 

135 self, 

136 *, 

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

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

139 credentials_file: Optional[str] = None, 

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

141 channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, 

142 api_mtls_endpoint: Optional[str] = None, 

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

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

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

146 quota_project_id: Optional[str] = None, 

147 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

148 always_use_jwt_access: Optional[bool] = False, 

149 api_audience: Optional[str] = None, 

150 ) -> None: 

151 """Instantiate the transport. 

152 

153 Args: 

154 host (Optional[str]): 

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

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

157 authorization credentials to attach to requests. These 

158 credentials identify the application to the service; if none 

159 are specified, the client will attempt to ascertain the 

160 credentials from the environment. 

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

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

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

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

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

166 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

167 ignored if a ``channel`` instance is provided. 

168 channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): 

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

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

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

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

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

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

175 a mutual TLS channel with client SSL credentials from 

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

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

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

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

180 ``api_mtls_endpoint`` is None. 

181 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

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

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

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

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

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

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

188 and quota. 

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

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

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

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

193 your own client library. 

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

195 be used for service account credentials. 

196 

197 Raises: 

198 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

199 creation failed for any reason. 

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

201 and ``credentials_file`` are passed. 

202 """ 

203 self._grpc_channel = None 

204 self._ssl_channel_credentials = ssl_channel_credentials 

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

206 

207 if api_mtls_endpoint: 

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

209 if client_cert_source: 

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

211 

212 if isinstance(channel, grpc.Channel): 

213 # Ignore credentials if a channel was passed. 

214 credentials = None 

215 self._ignore_credentials = True 

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

217 self._grpc_channel = channel 

218 self._ssl_channel_credentials = None 

219 

220 else: 

221 if api_mtls_endpoint: 

222 host = api_mtls_endpoint 

223 

224 # Create SSL credentials with client_cert_source or application 

225 # default SSL credentials. 

226 if client_cert_source: 

227 cert, key = client_cert_source() 

228 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

229 certificate_chain=cert, private_key=key 

230 ) 

231 else: 

232 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

233 

234 else: 

235 if client_cert_source_for_mtls and not ssl_channel_credentials: 

236 cert, key = client_cert_source_for_mtls() 

237 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

238 certificate_chain=cert, private_key=key 

239 ) 

240 

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

242 super().__init__( 

243 host=host, 

244 credentials=credentials, 

245 credentials_file=credentials_file, 

246 scopes=scopes, 

247 quota_project_id=quota_project_id, 

248 client_info=client_info, 

249 always_use_jwt_access=always_use_jwt_access, 

250 api_audience=api_audience, 

251 ) 

252 

253 if not self._grpc_channel: 

254 # initialize with the provided callable or the default channel 

255 channel_init = channel or type(self).create_channel 

256 self._grpc_channel = channel_init( 

257 self._host, 

258 # use the credentials which are saved 

259 credentials=self._credentials, 

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

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

262 credentials_file=None, 

263 scopes=self._scopes, 

264 ssl_credentials=self._ssl_channel_credentials, 

265 quota_project_id=quota_project_id, 

266 options=[ 

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

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

269 ], 

270 ) 

271 

272 self._interceptor = _LoggingClientInterceptor() 

273 self._logged_channel = grpc.intercept_channel( 

274 self._grpc_channel, self._interceptor 

275 ) 

276 

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

278 self._prep_wrapped_messages(client_info) 

279 

280 @classmethod 

281 def create_channel( 

282 cls, 

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

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

285 credentials_file: Optional[str] = None, 

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

287 quota_project_id: Optional[str] = None, 

288 **kwargs, 

289 ) -> grpc.Channel: 

290 """Create and return a gRPC channel object. 

291 Args: 

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

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

294 authorization credentials to attach to requests. These 

295 credentials identify this application to the service. If 

296 none are specified, the client will attempt to ascertain 

297 the credentials from the environment. 

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

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

300 This argument is mutually exclusive with credentials. This argument will be 

301 removed in the next major version of this library. 

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

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

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

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

306 and quota. 

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

308 channel creation. 

309 Returns: 

310 grpc.Channel: A gRPC channel object. 

311 

312 Raises: 

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

314 and ``credentials_file`` are passed. 

315 """ 

316 

317 return grpc_helpers.create_channel( 

318 host, 

319 credentials=credentials, 

320 credentials_file=credentials_file, 

321 quota_project_id=quota_project_id, 

322 default_scopes=cls.AUTH_SCOPES, 

323 scopes=scopes, 

324 default_host=cls.DEFAULT_HOST, 

325 **kwargs, 

326 ) 

327 

328 @property 

329 def grpc_channel(self) -> grpc.Channel: 

330 """Return the channel designed to connect to this service.""" 

331 return self._grpc_channel 

332 

333 @property 

334 def list_queues( 

335 self, 

336 ) -> Callable[[cloudtasks.ListQueuesRequest], cloudtasks.ListQueuesResponse]: 

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

338 

339 Lists queues. 

340 

341 Queues are returned in lexicographical order. 

342 

343 Returns: 

344 Callable[[~.ListQueuesRequest], 

345 ~.ListQueuesResponse]: 

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

347 on the server. 

348 """ 

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

350 # the request. 

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

352 # to pass in the functions for each. 

353 if "list_queues" not in self._stubs: 

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

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

356 request_serializer=cloudtasks.ListQueuesRequest.serialize, 

357 response_deserializer=cloudtasks.ListQueuesResponse.deserialize, 

358 ) 

359 return self._stubs["list_queues"] 

360 

361 @property 

362 def get_queue(self) -> Callable[[cloudtasks.GetQueueRequest], queue.Queue]: 

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

364 

365 Gets a queue. 

366 

367 Returns: 

368 Callable[[~.GetQueueRequest], 

369 ~.Queue]: 

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

371 on the server. 

372 """ 

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

374 # the request. 

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

376 # to pass in the functions for each. 

377 if "get_queue" not in self._stubs: 

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

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

380 request_serializer=cloudtasks.GetQueueRequest.serialize, 

381 response_deserializer=queue.Queue.deserialize, 

382 ) 

383 return self._stubs["get_queue"] 

384 

385 @property 

386 def create_queue( 

387 self, 

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

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

390 

391 Creates a queue. 

392 

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

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

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

396 

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

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

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

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

401 before using this method. 

402 

403 Returns: 

404 Callable[[~.CreateQueueRequest], 

405 ~.Queue]: 

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

407 on the server. 

408 """ 

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

410 # the request. 

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

412 # to pass in the functions for each. 

413 if "create_queue" not in self._stubs: 

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

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

416 request_serializer=cloudtasks.CreateQueueRequest.serialize, 

417 response_deserializer=gct_queue.Queue.deserialize, 

418 ) 

419 return self._stubs["create_queue"] 

420 

421 @property 

422 def update_queue( 

423 self, 

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

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

426 

427 Updates a queue. 

428 

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

430 the queue if it does exist. 

431 

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

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

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

435 

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

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

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

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

440 before using this method. 

441 

442 Returns: 

443 Callable[[~.UpdateQueueRequest], 

444 ~.Queue]: 

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

446 on the server. 

447 """ 

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

449 # the request. 

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

451 # to pass in the functions for each. 

452 if "update_queue" not in self._stubs: 

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

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

455 request_serializer=cloudtasks.UpdateQueueRequest.serialize, 

456 response_deserializer=gct_queue.Queue.deserialize, 

457 ) 

458 return self._stubs["update_queue"] 

459 

460 @property 

461 def delete_queue( 

462 self, 

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

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

465 

466 Deletes a queue. 

467 

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

469 

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

471 created for 7 days. 

472 

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

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

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

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

477 before using this method. 

478 

479 Returns: 

480 Callable[[~.DeleteQueueRequest], 

481 ~.Empty]: 

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

483 on the server. 

484 """ 

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

486 # the request. 

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

488 # to pass in the functions for each. 

489 if "delete_queue" not in self._stubs: 

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

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

492 request_serializer=cloudtasks.DeleteQueueRequest.serialize, 

493 response_deserializer=empty_pb2.Empty.FromString, 

494 ) 

495 return self._stubs["delete_queue"] 

496 

497 @property 

498 def purge_queue(self) -> Callable[[cloudtasks.PurgeQueueRequest], queue.Queue]: 

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

500 

501 Purges a queue by deleting all of its tasks. 

502 

503 All tasks created before this method is called are 

504 permanently deleted. 

505 

506 Purge operations can take up to one minute to take 

507 effect. Tasks might be dispatched before the purge takes 

508 effect. A purge is irreversible. 

509 

510 Returns: 

511 Callable[[~.PurgeQueueRequest], 

512 ~.Queue]: 

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

514 on the server. 

515 """ 

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

517 # the request. 

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

519 # to pass in the functions for each. 

520 if "purge_queue" not in self._stubs: 

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

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

523 request_serializer=cloudtasks.PurgeQueueRequest.serialize, 

524 response_deserializer=queue.Queue.deserialize, 

525 ) 

526 return self._stubs["purge_queue"] 

527 

528 @property 

529 def pause_queue(self) -> Callable[[cloudtasks.PauseQueueRequest], queue.Queue]: 

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

531 

532 Pauses the queue. 

533 

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

535 until the queue is resumed via 

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

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

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

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

540 

541 Returns: 

542 Callable[[~.PauseQueueRequest], 

543 ~.Queue]: 

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

545 on the server. 

546 """ 

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

548 # the request. 

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

550 # to pass in the functions for each. 

551 if "pause_queue" not in self._stubs: 

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

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

554 request_serializer=cloudtasks.PauseQueueRequest.serialize, 

555 response_deserializer=queue.Queue.deserialize, 

556 ) 

557 return self._stubs["pause_queue"] 

558 

559 @property 

560 def resume_queue(self) -> Callable[[cloudtasks.ResumeQueueRequest], queue.Queue]: 

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

562 

563 Resume a queue. 

564 

565 This method resumes a queue after it has been 

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

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

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

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

570 method it will be set to 

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

572 

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

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

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

576 Scaling 

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

578 

579 Returns: 

580 Callable[[~.ResumeQueueRequest], 

581 ~.Queue]: 

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

583 on the server. 

584 """ 

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

586 # the request. 

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

588 # to pass in the functions for each. 

589 if "resume_queue" not in self._stubs: 

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

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

592 request_serializer=cloudtasks.ResumeQueueRequest.serialize, 

593 response_deserializer=queue.Queue.deserialize, 

594 ) 

595 return self._stubs["resume_queue"] 

596 

597 @property 

598 def get_iam_policy( 

599 self, 

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

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

602 

603 Gets the access control policy for a 

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

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

606 

607 Authorization requires the following `Google 

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

609 specified resource parent: 

610 

611 - ``cloudtasks.queues.getIamPolicy`` 

612 

613 Returns: 

614 Callable[[~.GetIamPolicyRequest], 

615 ~.Policy]: 

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

617 on the server. 

618 """ 

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

620 # the request. 

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

622 # to pass in the functions for each. 

623 if "get_iam_policy" not in self._stubs: 

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

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

626 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

627 response_deserializer=policy_pb2.Policy.FromString, 

628 ) 

629 return self._stubs["get_iam_policy"] 

630 

631 @property 

632 def set_iam_policy( 

633 self, 

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

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

636 

637 Sets the access control policy for a 

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

639 policy. 

640 

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

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

643 the Cloud Console. 

644 

645 Authorization requires the following `Google 

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

647 specified resource parent: 

648 

649 - ``cloudtasks.queues.setIamPolicy`` 

650 

651 Returns: 

652 Callable[[~.SetIamPolicyRequest], 

653 ~.Policy]: 

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

655 on the server. 

656 """ 

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

658 # the request. 

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

660 # to pass in the functions for each. 

661 if "set_iam_policy" not in self._stubs: 

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

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

664 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

665 response_deserializer=policy_pb2.Policy.FromString, 

666 ) 

667 return self._stubs["set_iam_policy"] 

668 

669 @property 

670 def test_iam_permissions( 

671 self, 

672 ) -> Callable[ 

673 [iam_policy_pb2.TestIamPermissionsRequest], 

674 iam_policy_pb2.TestIamPermissionsResponse, 

675 ]: 

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

677 

678 Returns permissions that a caller has on a 

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

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

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

682 

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

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

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

686 warning. 

687 

688 Returns: 

689 Callable[[~.TestIamPermissionsRequest], 

690 ~.TestIamPermissionsResponse]: 

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

692 on the server. 

693 """ 

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

695 # the request. 

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

697 # to pass in the functions for each. 

698 if "test_iam_permissions" not in self._stubs: 

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

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

701 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

702 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

703 ) 

704 return self._stubs["test_iam_permissions"] 

705 

706 @property 

707 def list_tasks( 

708 self, 

709 ) -> Callable[[cloudtasks.ListTasksRequest], cloudtasks.ListTasksResponse]: 

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

711 

712 Lists the tasks in a queue. 

713 

714 By default, only the 

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

716 due to performance considerations; 

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

718 controls the subset of information which is returned. 

719 

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

721 at any time. 

722 

723 Returns: 

724 Callable[[~.ListTasksRequest], 

725 ~.ListTasksResponse]: 

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

727 on the server. 

728 """ 

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

730 # the request. 

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

732 # to pass in the functions for each. 

733 if "list_tasks" not in self._stubs: 

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

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

736 request_serializer=cloudtasks.ListTasksRequest.serialize, 

737 response_deserializer=cloudtasks.ListTasksResponse.deserialize, 

738 ) 

739 return self._stubs["list_tasks"] 

740 

741 @property 

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

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

744 

745 Gets a task. 

746 

747 Returns: 

748 Callable[[~.GetTaskRequest], 

749 ~.Task]: 

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

751 on the server. 

752 """ 

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

754 # the request. 

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

756 # to pass in the functions for each. 

757 if "get_task" not in self._stubs: 

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

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

760 request_serializer=cloudtasks.GetTaskRequest.serialize, 

761 response_deserializer=task.Task.deserialize, 

762 ) 

763 return self._stubs["get_task"] 

764 

765 @property 

766 def create_task(self) -> Callable[[cloudtasks.CreateTaskRequest], gct_task.Task]: 

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

768 

769 Creates a task and adds it to a queue. 

770 

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

772 command. 

773 

774 - The maximum task size is 100KB. 

775 

776 Returns: 

777 Callable[[~.CreateTaskRequest], 

778 ~.Task]: 

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

780 on the server. 

781 """ 

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

783 # the request. 

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

785 # to pass in the functions for each. 

786 if "create_task" not in self._stubs: 

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

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

789 request_serializer=cloudtasks.CreateTaskRequest.serialize, 

790 response_deserializer=gct_task.Task.deserialize, 

791 ) 

792 return self._stubs["create_task"] 

793 

794 @property 

795 def delete_task(self) -> Callable[[cloudtasks.DeleteTaskRequest], empty_pb2.Empty]: 

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

797 

798 Deletes a task. 

799 

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

801 A task cannot be deleted if it has executed successfully 

802 or permanently failed. 

803 

804 Returns: 

805 Callable[[~.DeleteTaskRequest], 

806 ~.Empty]: 

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

808 on the server. 

809 """ 

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

811 # the request. 

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

813 # to pass in the functions for each. 

814 if "delete_task" not in self._stubs: 

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

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

817 request_serializer=cloudtasks.DeleteTaskRequest.serialize, 

818 response_deserializer=empty_pb2.Empty.FromString, 

819 ) 

820 return self._stubs["delete_task"] 

821 

822 @property 

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

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

825 

826 Forces a task to run now. 

827 

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

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

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

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

832 

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

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

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

836 manually force a task to be dispatched now. 

837 

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

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

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

841 

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

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

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

845 be reset to the time that 

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

847 plus the retry delay specified in the queue's 

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

849 

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

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

852 task that has already succeeded or permanently failed. 

853 

854 Returns: 

855 Callable[[~.RunTaskRequest], 

856 ~.Task]: 

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

858 on the server. 

859 """ 

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

861 # the request. 

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

863 # to pass in the functions for each. 

864 if "run_task" not in self._stubs: 

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

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

867 request_serializer=cloudtasks.RunTaskRequest.serialize, 

868 response_deserializer=task.Task.deserialize, 

869 ) 

870 return self._stubs["run_task"] 

871 

872 def close(self): 

873 self._logged_channel.close() 

874 

875 @property 

876 def list_locations( 

877 self, 

878 ) -> Callable[ 

879 [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse 

880 ]: 

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

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

883 # the request. 

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

885 # to pass in the functions for each. 

886 if "list_locations" not in self._stubs: 

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

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

889 request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, 

890 response_deserializer=locations_pb2.ListLocationsResponse.FromString, 

891 ) 

892 return self._stubs["list_locations"] 

893 

894 @property 

895 def get_location( 

896 self, 

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

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

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

900 # the request. 

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

902 # to pass in the functions for each. 

903 if "get_location" not in self._stubs: 

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

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

906 request_serializer=locations_pb2.GetLocationRequest.SerializeToString, 

907 response_deserializer=locations_pb2.Location.FromString, 

908 ) 

909 return self._stubs["get_location"] 

910 

911 @property 

912 def kind(self) -> str: 

913 return "grpc" 

914 

915 

916__all__ = ("CloudTasksGrpcTransport",)