File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 1616
1717import asyncio
1818import os
19+ import signal
1920
2021import grpc
2122from grpc_reflection .v1alpha import reflection
3132 fnv1beta1 .DESCRIPTOR .services_by_name ["FunctionRunnerService" ].full_name ,
3233)
3334
35+ SHUTDOWN_GRACE_PERIOD_SECONDS = 5
36+
3437
3538def load_credentials (tls_certs_dir : str ) -> grpc .ServerCredentials :
3639 """Load TLS credentials for a composition function gRPC server.
@@ -90,6 +93,11 @@ def serve(
9093
9194 server = grpc .aio .server ()
9295
96+ loop .add_signal_handler (
97+ signal .SIGTERM ,
98+ lambda : asyncio .ensure_future (server .stop (grace = SHUTDOWN_GRACE_PERIOD_SECONDS )),
99+ )
100+
93101 grpcv1 .add_FunctionRunnerServiceServicer_to_server (function , server )
94102 grpcv1beta1 .add_FunctionRunnerServiceServicer_to_server (
95103 BetaFunctionRunner (wrapped = function ), server
@@ -116,7 +124,7 @@ async def start():
116124 try :
117125 loop .run_until_complete (start ())
118126 finally :
119- loop .run_until_complete (server .stop (grace = 5 ))
127+ loop .run_until_complete (server .stop (grace = SHUTDOWN_GRACE_PERIOD_SECONDS ))
120128 loop .close ()
121129
122130
You can’t perform that action at this time.
0 commit comments