17
17
import functools
18
18
import re
19
19
from typing import (
20
+ Callable ,
20
21
Dict ,
21
22
Mapping ,
22
23
MutableMapping ,
@@ -207,7 +208,9 @@ def __init__(
207
208
self ,
208
209
* ,
209
210
credentials : Optional [ga_credentials .Credentials ] = None ,
210
- transport : Union [str , BatchServiceTransport ] = "grpc_asyncio" ,
211
+ transport : Optional [
212
+ Union [str , BatchServiceTransport , Callable [..., BatchServiceTransport ]]
213
+ ] = "grpc_asyncio" ,
211
214
client_options : Optional [ClientOptions ] = None ,
212
215
client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
213
216
) -> None :
@@ -219,9 +222,11 @@ def __init__(
219
222
credentials identify the application to the service; if none
220
223
are specified, the client will attempt to ascertain the
221
224
credentials from the environment.
222
- transport (Union[str, ~.BatchServiceTransport]): The
223
- transport to use. If set to None, a transport is chosen
224
- automatically.
225
+ transport (Optional[Union[str,BatchServiceTransport,Callable[..., BatchServiceTransport]]]):
226
+ The transport to use, or a Callable that constructs and returns a new transport to use.
227
+ If a Callable is given, it will be called with the same set of initialization
228
+ arguments as used in the BatchServiceTransport constructor.
229
+ If set to None, a transport is chosen automatically.
225
230
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
226
231
Custom options for the client.
227
232
@@ -346,16 +351,19 @@ async def sample_create_job():
346
351
The Cloud Batch Job description.
347
352
"""
348
353
# Create or coerce a protobuf request object.
349
- # Quick check: If we got a request object, we should *not* have
350
- # gotten any keyword arguments that map to the request.
354
+ # - Quick check: If we got a request object, we should *not* have
355
+ # gotten any keyword arguments that map to the request.
351
356
has_flattened_params = any ([parent , job , job_id ])
352
357
if request is not None and has_flattened_params :
353
358
raise ValueError (
354
359
"If the `request` argument is set, then none of "
355
360
"the individual field arguments should be set."
356
361
)
357
362
358
- request = batch .CreateJobRequest (request )
363
+ # - Use the request object if provided (there's no risk of modifying the input as
364
+ # there are no flattened fields), or create one.
365
+ if not isinstance (request , batch .CreateJobRequest ):
366
+ request = batch .CreateJobRequest (request )
359
367
360
368
# If we have keyword arguments corresponding to fields on the
361
369
# request, apply these.
@@ -368,11 +376,9 @@ async def sample_create_job():
368
376
369
377
# Wrap the RPC method; this adds retry and timeout information,
370
378
# and friendly error handling.
371
- rpc = gapic_v1 .method_async .wrap_method (
372
- self ._client ._transport .create_job ,
373
- default_timeout = 60.0 ,
374
- client_info = DEFAULT_CLIENT_INFO ,
375
- )
379
+ rpc = self ._client ._transport ._wrapped_methods [
380
+ self ._client ._transport .create_job
381
+ ]
376
382
377
383
# Certain fields should be provided within the metadata header;
378
384
# add these here.
@@ -450,16 +456,19 @@ async def sample_get_job():
450
456
The Cloud Batch Job description.
451
457
"""
452
458
# Create or coerce a protobuf request object.
453
- # Quick check: If we got a request object, we should *not* have
454
- # gotten any keyword arguments that map to the request.
459
+ # - Quick check: If we got a request object, we should *not* have
460
+ # gotten any keyword arguments that map to the request.
455
461
has_flattened_params = any ([name ])
456
462
if request is not None and has_flattened_params :
457
463
raise ValueError (
458
464
"If the `request` argument is set, then none of "
459
465
"the individual field arguments should be set."
460
466
)
461
467
462
- request = batch .GetJobRequest (request )
468
+ # - Use the request object if provided (there's no risk of modifying the input as
469
+ # there are no flattened fields), or create one.
470
+ if not isinstance (request , batch .GetJobRequest ):
471
+ request = batch .GetJobRequest (request )
463
472
464
473
# If we have keyword arguments corresponding to fields on the
465
474
# request, apply these.
@@ -468,20 +477,7 @@ async def sample_get_job():
468
477
469
478
# Wrap the RPC method; this adds retry and timeout information,
470
479
# and friendly error handling.
471
- rpc = gapic_v1 .method_async .wrap_method (
472
- self ._client ._transport .get_job ,
473
- default_retry = retries .AsyncRetry (
474
- initial = 1.0 ,
475
- maximum = 10.0 ,
476
- multiplier = 1.3 ,
477
- predicate = retries .if_exception_type (
478
- core_exceptions .ServiceUnavailable ,
479
- ),
480
- deadline = 60.0 ,
481
- ),
482
- default_timeout = 60.0 ,
483
- client_info = DEFAULT_CLIENT_INFO ,
484
- )
480
+ rpc = self ._client ._transport ._wrapped_methods [self ._client ._transport .get_job ]
485
481
486
482
# Certain fields should be provided within the metadata header;
487
483
# add these here.
@@ -574,16 +570,19 @@ async def sample_delete_job():
574
570
575
571
"""
576
572
# Create or coerce a protobuf request object.
577
- # Quick check: If we got a request object, we should *not* have
578
- # gotten any keyword arguments that map to the request.
573
+ # - Quick check: If we got a request object, we should *not* have
574
+ # gotten any keyword arguments that map to the request.
579
575
has_flattened_params = any ([name ])
580
576
if request is not None and has_flattened_params :
581
577
raise ValueError (
582
578
"If the `request` argument is set, then none of "
583
579
"the individual field arguments should be set."
584
580
)
585
581
586
- request = batch .DeleteJobRequest (request )
582
+ # - Use the request object if provided (there's no risk of modifying the input as
583
+ # there are no flattened fields), or create one.
584
+ if not isinstance (request , batch .DeleteJobRequest ):
585
+ request = batch .DeleteJobRequest (request )
587
586
588
587
# If we have keyword arguments corresponding to fields on the
589
588
# request, apply these.
@@ -592,11 +591,9 @@ async def sample_delete_job():
592
591
593
592
# Wrap the RPC method; this adds retry and timeout information,
594
593
# and friendly error handling.
595
- rpc = gapic_v1 .method_async .wrap_method (
596
- self ._client ._transport .delete_job ,
597
- default_timeout = 60.0 ,
598
- client_info = DEFAULT_CLIENT_INFO ,
599
- )
594
+ rpc = self ._client ._transport ._wrapped_methods [
595
+ self ._client ._transport .delete_job
596
+ ]
600
597
601
598
# Certain fields should be provided within the metadata header;
602
599
# add these here.
@@ -687,16 +684,19 @@ async def sample_list_jobs():
687
684
688
685
"""
689
686
# Create or coerce a protobuf request object.
690
- # Quick check: If we got a request object, we should *not* have
691
- # gotten any keyword arguments that map to the request.
687
+ # - Quick check: If we got a request object, we should *not* have
688
+ # gotten any keyword arguments that map to the request.
692
689
has_flattened_params = any ([parent ])
693
690
if request is not None and has_flattened_params :
694
691
raise ValueError (
695
692
"If the `request` argument is set, then none of "
696
693
"the individual field arguments should be set."
697
694
)
698
695
699
- request = batch .ListJobsRequest (request )
696
+ # - Use the request object if provided (there's no risk of modifying the input as
697
+ # there are no flattened fields), or create one.
698
+ if not isinstance (request , batch .ListJobsRequest ):
699
+ request = batch .ListJobsRequest (request )
700
700
701
701
# If we have keyword arguments corresponding to fields on the
702
702
# request, apply these.
@@ -705,20 +705,9 @@ async def sample_list_jobs():
705
705
706
706
# Wrap the RPC method; this adds retry and timeout information,
707
707
# and friendly error handling.
708
- rpc = gapic_v1 .method_async .wrap_method (
709
- self ._client ._transport .list_jobs ,
710
- default_retry = retries .AsyncRetry (
711
- initial = 1.0 ,
712
- maximum = 10.0 ,
713
- multiplier = 1.3 ,
714
- predicate = retries .if_exception_type (
715
- core_exceptions .ServiceUnavailable ,
716
- ),
717
- deadline = 60.0 ,
718
- ),
719
- default_timeout = 60.0 ,
720
- client_info = DEFAULT_CLIENT_INFO ,
721
- )
708
+ rpc = self ._client ._transport ._wrapped_methods [
709
+ self ._client ._transport .list_jobs
710
+ ]
722
711
723
712
# Certain fields should be provided within the metadata header;
724
713
# add these here.
@@ -805,16 +794,19 @@ async def sample_get_task():
805
794
A Cloud Batch task.
806
795
"""
807
796
# Create or coerce a protobuf request object.
808
- # Quick check: If we got a request object, we should *not* have
809
- # gotten any keyword arguments that map to the request.
797
+ # - Quick check: If we got a request object, we should *not* have
798
+ # gotten any keyword arguments that map to the request.
810
799
has_flattened_params = any ([name ])
811
800
if request is not None and has_flattened_params :
812
801
raise ValueError (
813
802
"If the `request` argument is set, then none of "
814
803
"the individual field arguments should be set."
815
804
)
816
805
817
- request = batch .GetTaskRequest (request )
806
+ # - Use the request object if provided (there's no risk of modifying the input as
807
+ # there are no flattened fields), or create one.
808
+ if not isinstance (request , batch .GetTaskRequest ):
809
+ request = batch .GetTaskRequest (request )
818
810
819
811
# If we have keyword arguments corresponding to fields on the
820
812
# request, apply these.
@@ -823,20 +815,7 @@ async def sample_get_task():
823
815
824
816
# Wrap the RPC method; this adds retry and timeout information,
825
817
# and friendly error handling.
826
- rpc = gapic_v1 .method_async .wrap_method (
827
- self ._client ._transport .get_task ,
828
- default_retry = retries .AsyncRetry (
829
- initial = 1.0 ,
830
- maximum = 10.0 ,
831
- multiplier = 1.3 ,
832
- predicate = retries .if_exception_type (
833
- core_exceptions .ServiceUnavailable ,
834
- ),
835
- deadline = 60.0 ,
836
- ),
837
- default_timeout = 60.0 ,
838
- client_info = DEFAULT_CLIENT_INFO ,
839
- )
818
+ rpc = self ._client ._transport ._wrapped_methods [self ._client ._transport .get_task ]
840
819
841
820
# Certain fields should be provided within the metadata header;
842
821
# add these here.
@@ -923,16 +902,19 @@ async def sample_list_tasks():
923
902
924
903
"""
925
904
# Create or coerce a protobuf request object.
926
- # Quick check: If we got a request object, we should *not* have
927
- # gotten any keyword arguments that map to the request.
905
+ # - Quick check: If we got a request object, we should *not* have
906
+ # gotten any keyword arguments that map to the request.
928
907
has_flattened_params = any ([parent ])
929
908
if request is not None and has_flattened_params :
930
909
raise ValueError (
931
910
"If the `request` argument is set, then none of "
932
911
"the individual field arguments should be set."
933
912
)
934
913
935
- request = batch .ListTasksRequest (request )
914
+ # - Use the request object if provided (there's no risk of modifying the input as
915
+ # there are no flattened fields), or create one.
916
+ if not isinstance (request , batch .ListTasksRequest ):
917
+ request = batch .ListTasksRequest (request )
936
918
937
919
# If we have keyword arguments corresponding to fields on the
938
920
# request, apply these.
@@ -941,20 +923,9 @@ async def sample_list_tasks():
941
923
942
924
# Wrap the RPC method; this adds retry and timeout information,
943
925
# and friendly error handling.
944
- rpc = gapic_v1 .method_async .wrap_method (
945
- self ._client ._transport .list_tasks ,
946
- default_retry = retries .AsyncRetry (
947
- initial = 1.0 ,
948
- maximum = 10.0 ,
949
- multiplier = 1.3 ,
950
- predicate = retries .if_exception_type (
951
- core_exceptions .ServiceUnavailable ,
952
- ),
953
- deadline = 60.0 ,
954
- ),
955
- default_timeout = 60.0 ,
956
- client_info = DEFAULT_CLIENT_INFO ,
957
- )
926
+ rpc = self ._client ._transport ._wrapped_methods [
927
+ self ._client ._transport .list_tasks
928
+ ]
958
929
959
930
# Certain fields should be provided within the metadata header;
960
931
# add these here.
0 commit comments