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

134 statements  

« 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 Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union 

17import warnings 

18 

19from google.api_core import gapic_v1, grpc_helpers_async 

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

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

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

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

24from google.protobuf import empty_pb2 # type: ignore 

25import grpc # type: ignore 

26from grpc.experimental import aio # type: ignore 

27 

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 

33 

34from .base import DEFAULT_CLIENT_INFO, CloudTasksTransport 

35from .grpc import CloudTasksGrpcTransport 

36 

37 

38class CloudTasksGrpcAsyncIOTransport(CloudTasksTransport): 

39 """gRPC AsyncIO backend transport for CloudTasks. 

40 

41 Cloud Tasks allows developers to manage the execution of 

42 background work in their applications. 

43 

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

45 primary client can load the underlying transport implementation 

46 and call it. 

47 

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

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

50 """ 

51 

52 _grpc_channel: aio.Channel 

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

54 

55 @classmethod 

56 def create_channel( 

57 cls, 

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

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

60 credentials_file: Optional[str] = None, 

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

62 quota_project_id: Optional[str] = None, 

63 **kwargs, 

64 ) -> aio.Channel: 

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

66 Args: 

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

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

69 authorization credentials to attach to requests. These 

70 credentials identify this application to the service. If 

71 none are specified, the client will attempt to ascertain 

72 the credentials from the environment. 

73 credentials_file (Optional[str]): A file with credentials that can 

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

75 This argument is ignored if ``channel`` is provided. 

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

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

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

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

80 and quota. 

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

82 channel creation. 

83 Returns: 

84 aio.Channel: A gRPC AsyncIO channel object. 

85 """ 

86 

87 return grpc_helpers_async.create_channel( 

88 host, 

89 credentials=credentials, 

90 credentials_file=credentials_file, 

91 quota_project_id=quota_project_id, 

92 default_scopes=cls.AUTH_SCOPES, 

93 scopes=scopes, 

94 default_host=cls.DEFAULT_HOST, 

95 **kwargs, 

96 ) 

97 

98 def __init__( 

99 self, 

100 *, 

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

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

103 credentials_file: Optional[str] = None, 

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

105 channel: Optional[aio.Channel] = None, 

106 api_mtls_endpoint: Optional[str] = None, 

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

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

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

110 quota_project_id: Optional[str] = None, 

111 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

112 always_use_jwt_access: Optional[bool] = False, 

113 api_audience: Optional[str] = None, 

114 ) -> None: 

115 """Instantiate the transport. 

116 

117 Args: 

118 host (Optional[str]): 

119 The hostname to connect to. 

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

121 authorization credentials to attach to requests. These 

122 credentials identify the application to the service; if none 

123 are specified, the client will attempt to ascertain the 

124 credentials from the environment. 

125 This argument is ignored if ``channel`` is provided. 

126 credentials_file (Optional[str]): A file with credentials that can 

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

128 This argument is ignored if ``channel`` is provided. 

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

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

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

132 channel (Optional[aio.Channel]): A ``Channel`` instance through 

133 which to make calls. 

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

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

136 a mutual TLS channel with client SSL credentials from 

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

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

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

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

141 ``api_mtls_endpoint`` is None. 

142 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

143 for the grpc channel. It is ignored if ``channel`` is provided. 

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

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

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

147 ignored if ``channel`` or ``ssl_channel_credentials`` is provided. 

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

149 and quota. 

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

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

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

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

154 your own client library. 

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

156 be used for service account credentials. 

157 

158 Raises: 

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

160 creation failed for any reason. 

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

162 and ``credentials_file`` are passed. 

163 """ 

164 self._grpc_channel = None 

165 self._ssl_channel_credentials = ssl_channel_credentials 

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

167 

168 if api_mtls_endpoint: 

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

170 if client_cert_source: 

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

172 

173 if channel: 

174 # Ignore credentials if a channel was passed. 

175 credentials = False 

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

177 self._grpc_channel = channel 

178 self._ssl_channel_credentials = None 

179 else: 

180 if api_mtls_endpoint: 

181 host = api_mtls_endpoint 

182 

183 # Create SSL credentials with client_cert_source or application 

184 # default SSL credentials. 

185 if client_cert_source: 

186 cert, key = client_cert_source() 

187 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

188 certificate_chain=cert, private_key=key 

189 ) 

190 else: 

191 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

192 

193 else: 

194 if client_cert_source_for_mtls and not ssl_channel_credentials: 

195 cert, key = client_cert_source_for_mtls() 

196 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

197 certificate_chain=cert, private_key=key 

198 ) 

199 

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

201 super().__init__( 

202 host=host, 

203 credentials=credentials, 

204 credentials_file=credentials_file, 

205 scopes=scopes, 

206 quota_project_id=quota_project_id, 

207 client_info=client_info, 

208 always_use_jwt_access=always_use_jwt_access, 

209 api_audience=api_audience, 

210 ) 

211 

212 if not self._grpc_channel: 

213 self._grpc_channel = type(self).create_channel( 

214 self._host, 

215 # use the credentials which are saved 

216 credentials=self._credentials, 

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

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

219 credentials_file=None, 

220 scopes=self._scopes, 

221 ssl_credentials=self._ssl_channel_credentials, 

222 quota_project_id=quota_project_id, 

223 options=[ 

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

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

226 ], 

227 ) 

228 

229 # Wrap messages. This must be done after self._grpc_channel exists 

230 self._prep_wrapped_messages(client_info) 

231 

232 @property 

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

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

235 

236 This property caches on the instance; repeated calls return 

237 the same channel. 

238 """ 

239 # Return the channel from cache. 

240 return self._grpc_channel 

241 

242 @property 

243 def list_queues( 

244 self, 

245 ) -> Callable[ 

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

247 ]: 

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

249 

250 Lists queues. 

251 Queues are returned in lexicographical order. 

252 

253 Returns: 

254 Callable[[~.ListQueuesRequest], 

255 Awaitable[~.ListQueuesResponse]]: 

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

257 on the server. 

258 """ 

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

260 # the request. 

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

262 # to pass in the functions for each. 

263 if "list_queues" not in self._stubs: 

264 self._stubs["list_queues"] = self.grpc_channel.unary_unary( 

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

266 request_serializer=cloudtasks.ListQueuesRequest.serialize, 

267 response_deserializer=cloudtasks.ListQueuesResponse.deserialize, 

268 ) 

269 return self._stubs["list_queues"] 

270 

271 @property 

272 def get_queue( 

273 self, 

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

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

276 

277 Gets a queue. 

278 

279 Returns: 

280 Callable[[~.GetQueueRequest], 

281 Awaitable[~.Queue]]: 

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

283 on the server. 

284 """ 

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

286 # the request. 

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

288 # to pass in the functions for each. 

289 if "get_queue" not in self._stubs: 

290 self._stubs["get_queue"] = self.grpc_channel.unary_unary( 

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

292 request_serializer=cloudtasks.GetQueueRequest.serialize, 

293 response_deserializer=queue.Queue.deserialize, 

294 ) 

295 return self._stubs["get_queue"] 

296 

297 @property 

298 def create_queue( 

299 self, 

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

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

302 

303 Creates a queue. 

304 

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

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

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

308 

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

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

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

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

313 before using this method. 

314 

315 Returns: 

316 Callable[[~.CreateQueueRequest], 

317 Awaitable[~.Queue]]: 

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

319 on the server. 

320 """ 

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

322 # the request. 

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

324 # to pass in the functions for each. 

325 if "create_queue" not in self._stubs: 

326 self._stubs["create_queue"] = self.grpc_channel.unary_unary( 

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

328 request_serializer=cloudtasks.CreateQueueRequest.serialize, 

329 response_deserializer=gct_queue.Queue.deserialize, 

330 ) 

331 return self._stubs["create_queue"] 

332 

333 @property 

334 def update_queue( 

335 self, 

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

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

338 

339 Updates a queue. 

340 

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

342 the queue if it does exist. 

343 

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

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

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

347 

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

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

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

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

352 before using this method. 

353 

354 Returns: 

355 Callable[[~.UpdateQueueRequest], 

356 Awaitable[~.Queue]]: 

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

358 on the server. 

359 """ 

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

361 # the request. 

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

363 # to pass in the functions for each. 

364 if "update_queue" not in self._stubs: 

365 self._stubs["update_queue"] = self.grpc_channel.unary_unary( 

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

367 request_serializer=cloudtasks.UpdateQueueRequest.serialize, 

368 response_deserializer=gct_queue.Queue.deserialize, 

369 ) 

370 return self._stubs["update_queue"] 

371 

372 @property 

373 def delete_queue( 

374 self, 

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

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

377 

378 Deletes a queue. 

379 

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

381 

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

383 created for 7 days. 

384 

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

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

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

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

389 before using this method. 

390 

391 Returns: 

392 Callable[[~.DeleteQueueRequest], 

393 Awaitable[~.Empty]]: 

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

395 on the server. 

396 """ 

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

398 # the request. 

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

400 # to pass in the functions for each. 

401 if "delete_queue" not in self._stubs: 

402 self._stubs["delete_queue"] = self.grpc_channel.unary_unary( 

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

404 request_serializer=cloudtasks.DeleteQueueRequest.serialize, 

405 response_deserializer=empty_pb2.Empty.FromString, 

406 ) 

407 return self._stubs["delete_queue"] 

408 

409 @property 

410 def purge_queue( 

411 self, 

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

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

414 

415 Purges a queue by deleting all of its tasks. 

416 All tasks created before this method is called are 

417 permanently deleted. 

418 Purge operations can take up to one minute to take 

419 effect. Tasks might be dispatched before the purge takes 

420 effect. A purge is irreversible. 

421 

422 Returns: 

423 Callable[[~.PurgeQueueRequest], 

424 Awaitable[~.Queue]]: 

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

426 on the server. 

427 """ 

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

429 # the request. 

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

431 # to pass in the functions for each. 

432 if "purge_queue" not in self._stubs: 

433 self._stubs["purge_queue"] = self.grpc_channel.unary_unary( 

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

435 request_serializer=cloudtasks.PurgeQueueRequest.serialize, 

436 response_deserializer=queue.Queue.deserialize, 

437 ) 

438 return self._stubs["purge_queue"] 

439 

440 @property 

441 def pause_queue( 

442 self, 

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

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

445 

446 Pauses the queue. 

447 

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

449 until the queue is resumed via 

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

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

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

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

454 

455 Returns: 

456 Callable[[~.PauseQueueRequest], 

457 Awaitable[~.Queue]]: 

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

459 on the server. 

460 """ 

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

462 # the request. 

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

464 # to pass in the functions for each. 

465 if "pause_queue" not in self._stubs: 

466 self._stubs["pause_queue"] = self.grpc_channel.unary_unary( 

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

468 request_serializer=cloudtasks.PauseQueueRequest.serialize, 

469 response_deserializer=queue.Queue.deserialize, 

470 ) 

471 return self._stubs["pause_queue"] 

472 

473 @property 

474 def resume_queue( 

475 self, 

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

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

478 

479 Resume a queue. 

480 

481 This method resumes a queue after it has been 

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

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

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

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

486 method it will be set to 

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

488 

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

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

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

492 Scaling 

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

494 

495 Returns: 

496 Callable[[~.ResumeQueueRequest], 

497 Awaitable[~.Queue]]: 

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

499 on the server. 

500 """ 

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

502 # the request. 

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

504 # to pass in the functions for each. 

505 if "resume_queue" not in self._stubs: 

506 self._stubs["resume_queue"] = self.grpc_channel.unary_unary( 

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

508 request_serializer=cloudtasks.ResumeQueueRequest.serialize, 

509 response_deserializer=queue.Queue.deserialize, 

510 ) 

511 return self._stubs["resume_queue"] 

512 

513 @property 

514 def get_iam_policy( 

515 self, 

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

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

518 

519 Gets the access control policy for a 

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

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

522 

523 Authorization requires the following `Google 

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

525 specified resource parent: 

526 

527 - ``cloudtasks.queues.getIamPolicy`` 

528 

529 Returns: 

530 Callable[[~.GetIamPolicyRequest], 

531 Awaitable[~.Policy]]: 

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

533 on the server. 

534 """ 

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

536 # the request. 

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

538 # to pass in the functions for each. 

539 if "get_iam_policy" not in self._stubs: 

540 self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( 

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

542 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

543 response_deserializer=policy_pb2.Policy.FromString, 

544 ) 

545 return self._stubs["get_iam_policy"] 

546 

547 @property 

548 def set_iam_policy( 

549 self, 

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

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

552 

553 Sets the access control policy for a 

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

555 policy. 

556 

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

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

559 the Cloud Console. 

560 

561 Authorization requires the following `Google 

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

563 specified resource parent: 

564 

565 - ``cloudtasks.queues.setIamPolicy`` 

566 

567 Returns: 

568 Callable[[~.SetIamPolicyRequest], 

569 Awaitable[~.Policy]]: 

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

571 on the server. 

572 """ 

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

574 # the request. 

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

576 # to pass in the functions for each. 

577 if "set_iam_policy" not in self._stubs: 

578 self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( 

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

580 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

581 response_deserializer=policy_pb2.Policy.FromString, 

582 ) 

583 return self._stubs["set_iam_policy"] 

584 

585 @property 

586 def test_iam_permissions( 

587 self, 

588 ) -> Callable[ 

589 [iam_policy_pb2.TestIamPermissionsRequest], 

590 Awaitable[iam_policy_pb2.TestIamPermissionsResponse], 

591 ]: 

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

593 

594 Returns permissions that a caller has on a 

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

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

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

598 

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

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

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

602 warning. 

603 

604 Returns: 

605 Callable[[~.TestIamPermissionsRequest], 

606 Awaitable[~.TestIamPermissionsResponse]]: 

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

608 on the server. 

609 """ 

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

611 # the request. 

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

613 # to pass in the functions for each. 

614 if "test_iam_permissions" not in self._stubs: 

615 self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( 

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

617 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

618 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

619 ) 

620 return self._stubs["test_iam_permissions"] 

621 

622 @property 

623 def list_tasks( 

624 self, 

625 ) -> Callable[ 

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

627 ]: 

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

629 

630 Lists the tasks in a queue. 

631 

632 By default, only the 

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

634 due to performance considerations; 

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

636 controls the subset of information which is returned. 

637 

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

639 at any time. 

640 

641 Returns: 

642 Callable[[~.ListTasksRequest], 

643 Awaitable[~.ListTasksResponse]]: 

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

645 on the server. 

646 """ 

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

648 # the request. 

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

650 # to pass in the functions for each. 

651 if "list_tasks" not in self._stubs: 

652 self._stubs["list_tasks"] = self.grpc_channel.unary_unary( 

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

654 request_serializer=cloudtasks.ListTasksRequest.serialize, 

655 response_deserializer=cloudtasks.ListTasksResponse.deserialize, 

656 ) 

657 return self._stubs["list_tasks"] 

658 

659 @property 

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

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

662 

663 Gets a task. 

664 

665 Returns: 

666 Callable[[~.GetTaskRequest], 

667 Awaitable[~.Task]]: 

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

669 on the server. 

670 """ 

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

672 # the request. 

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

674 # to pass in the functions for each. 

675 if "get_task" not in self._stubs: 

676 self._stubs["get_task"] = self.grpc_channel.unary_unary( 

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

678 request_serializer=cloudtasks.GetTaskRequest.serialize, 

679 response_deserializer=task.Task.deserialize, 

680 ) 

681 return self._stubs["get_task"] 

682 

683 @property 

684 def create_task( 

685 self, 

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

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

688 

689 Creates a task and adds it to a queue. 

690 

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

692 command. 

693 

694 - The maximum task size is 100KB. 

695 

696 Returns: 

697 Callable[[~.CreateTaskRequest], 

698 Awaitable[~.Task]]: 

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

700 on the server. 

701 """ 

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

703 # the request. 

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

705 # to pass in the functions for each. 

706 if "create_task" not in self._stubs: 

707 self._stubs["create_task"] = self.grpc_channel.unary_unary( 

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

709 request_serializer=cloudtasks.CreateTaskRequest.serialize, 

710 response_deserializer=gct_task.Task.deserialize, 

711 ) 

712 return self._stubs["create_task"] 

713 

714 @property 

715 def delete_task( 

716 self, 

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

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

719 

720 Deletes a task. 

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

722 A task cannot be deleted if it has executed successfully 

723 or permanently failed. 

724 

725 Returns: 

726 Callable[[~.DeleteTaskRequest], 

727 Awaitable[~.Empty]]: 

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

729 on the server. 

730 """ 

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

732 # the request. 

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

734 # to pass in the functions for each. 

735 if "delete_task" not in self._stubs: 

736 self._stubs["delete_task"] = self.grpc_channel.unary_unary( 

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

738 request_serializer=cloudtasks.DeleteTaskRequest.serialize, 

739 response_deserializer=empty_pb2.Empty.FromString, 

740 ) 

741 return self._stubs["delete_task"] 

742 

743 @property 

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

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

746 

747 Forces a task to run now. 

748 

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

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

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

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

753 

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

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

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

757 manually force a task to be dispatched now. 

758 

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

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

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

762 

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

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

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

766 be reset to the time that 

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

768 plus the retry delay specified in the queue's 

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

770 

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

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

773 task that has already succeeded or permanently failed. 

774 

775 Returns: 

776 Callable[[~.RunTaskRequest], 

777 Awaitable[~.Task]]: 

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

779 on the server. 

780 """ 

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

782 # the request. 

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

784 # to pass in the functions for each. 

785 if "run_task" not in self._stubs: 

786 self._stubs["run_task"] = self.grpc_channel.unary_unary( 

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

788 request_serializer=cloudtasks.RunTaskRequest.serialize, 

789 response_deserializer=task.Task.deserialize, 

790 ) 

791 return self._stubs["run_task"] 

792 

793 def close(self): 

794 return self.grpc_channel.close() 

795 

796 

797__all__ = ("CloudTasksGrpcAsyncIOTransport",)