@@ -69,8 +69,11 @@ class ReduceStreamAsyncServer(NumaflowServer):
6969 sock_path: The UNIX socket path to be used for the server
7070 max_message_size: The max message size in bytes the server can receive and send
7171 max_threads: The max number of threads to be spawned;
72- defaults to 4 and max capped at 16
72+ defaults to 4 and max capped at 16
7373 server_info_file: The path to the server info file
74+ shutdown_callback: Callable, executed after loop is stopped, before
75+ cancelling any tasks.
76+ Useful for graceful shutdown.
7477
7578 Example invocation:
7679 ```py
@@ -138,13 +141,15 @@ def __init__(
138141 max_message_size = MAX_MESSAGE_SIZE ,
139142 max_threads = NUM_THREADS_DEFAULT ,
140143 server_info_file = REDUCE_STREAM_SERVER_INFO_FILE_PATH ,
144+ shutdown_callback = None ,
141145 ):
142146 init_kwargs = init_kwargs or {}
143147 self .reduce_stream_handler = get_handler (reduce_stream_instance , init_args , init_kwargs )
144148 self .sock_path = f"unix://{ sock_path } "
145149 self .max_message_size = max_message_size
146150 self .max_threads = min (max_threads , MAX_NUM_THREADS )
147151 self .server_info_file = server_info_file
152+ self .shutdown_callback = shutdown_callback
148153
149154 self ._server_options = [
150155 ("grpc.max_send_message_length" , self .max_message_size ),
@@ -161,7 +166,7 @@ def start(self):
161166 _LOGGER .info (
162167 "Starting Async Reduce Stream Server" ,
163168 )
164- aiorun .run (self .aexec (), use_uvloop = True )
169+ aiorun .run (self .aexec (), use_uvloop = True , shutdown_callback = self . shutdown_callback )
165170
166171 async def aexec (self ):
167172 """
0 commit comments