Merge pull request #140 from negz/terminal
Shutdown gracefully on SIGTERM
This commit is contained in:
commit
3931d503fc
|
@ -45,8 +45,8 @@ def update(r: fnv1.Resource, source: dict | structpb.Struct | pydantic.BaseModel
|
||||||
# apiVersion is set to its default value 's3.aws.upbound.io/v1beta2'
|
# apiVersion is set to its default value 's3.aws.upbound.io/v1beta2'
|
||||||
# (and not explicitly provided during initialization), it will be
|
# (and not explicitly provided during initialization), it will be
|
||||||
# excluded from the serialized output.
|
# excluded from the serialized output.
|
||||||
data['apiVersion'] = source.apiVersion
|
data["apiVersion"] = source.apiVersion
|
||||||
data['kind'] = source.kind
|
data["kind"] = source.kind
|
||||||
r.resource.update(data)
|
r.resource.update(data)
|
||||||
case structpb.Struct():
|
case structpb.Struct():
|
||||||
# TODO(negz): Use struct_to_dict and update to match other semantics?
|
# TODO(negz): Use struct_to_dict and update to match other semantics?
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
|
|
||||||
import grpc
|
import grpc
|
||||||
from grpc_reflection.v1alpha import reflection
|
from grpc_reflection.v1alpha import reflection
|
||||||
|
@ -31,6 +32,8 @@ SERVICE_NAMES = (
|
||||||
fnv1beta1.DESCRIPTOR.services_by_name["FunctionRunnerService"].full_name,
|
fnv1beta1.DESCRIPTOR.services_by_name["FunctionRunnerService"].full_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SHUTDOWN_GRACE_PERIOD_SECONDS = 5
|
||||||
|
|
||||||
|
|
||||||
def load_credentials(tls_certs_dir: str) -> grpc.ServerCredentials:
|
def load_credentials(tls_certs_dir: str) -> grpc.ServerCredentials:
|
||||||
"""Load TLS credentials for a composition function gRPC server.
|
"""Load TLS credentials for a composition function gRPC server.
|
||||||
|
@ -90,6 +93,11 @@ def serve(
|
||||||
|
|
||||||
server = grpc.aio.server()
|
server = grpc.aio.server()
|
||||||
|
|
||||||
|
loop.add_signal_handler(
|
||||||
|
signal.SIGTERM,
|
||||||
|
lambda: asyncio.ensure_future(server.stop(grace=SHUTDOWN_GRACE_PERIOD_SECONDS)),
|
||||||
|
)
|
||||||
|
|
||||||
grpcv1.add_FunctionRunnerServiceServicer_to_server(function, server)
|
grpcv1.add_FunctionRunnerServiceServicer_to_server(function, server)
|
||||||
grpcv1beta1.add_FunctionRunnerServiceServicer_to_server(
|
grpcv1beta1.add_FunctionRunnerServiceServicer_to_server(
|
||||||
BetaFunctionRunner(wrapped=function), server
|
BetaFunctionRunner(wrapped=function), server
|
||||||
|
@ -116,7 +124,7 @@ def serve(
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(start())
|
loop.run_until_complete(start())
|
||||||
finally:
|
finally:
|
||||||
loop.run_until_complete(server.stop(grace=5))
|
loop.run_until_complete(server.stop(grace=SHUTDOWN_GRACE_PERIOD_SECONDS))
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue