|
33 | 33 | from genkit.web.requests import (
|
34 | 34 | is_streaming_requested,
|
35 | 35 | )
|
| 36 | +from genkit.web.servers.signals import terminate_all_servers |
36 | 37 | from genkit.web.typing import (
|
37 | 38 | Application,
|
38 | 39 | LifespanHandler,
|
@@ -249,6 +250,19 @@ async def health_check(request: Request) -> JSONResponse:
|
249 | 250 | """
|
250 | 251 | return JSONResponse(content={'status': 'OK'})
|
251 | 252 |
|
| 253 | + async def terminate(request: Request) -> JSONResponse: |
| 254 | + """Handle the quit endpoint. |
| 255 | +
|
| 256 | + Args: |
| 257 | + request: The Starlette request object. |
| 258 | +
|
| 259 | + Returns: |
| 260 | + An empty JSON response with status code 200. |
| 261 | + """ |
| 262 | + await logger.ainfo('Shutting down servers...') |
| 263 | + terminate_all_servers() |
| 264 | + return JSONResponse(content={'status': 'OK'}) |
| 265 | + |
252 | 266 | async def list_actions(request: Request) -> JSONResponse:
|
253 | 267 | """Handle the request for listing available actions.
|
254 | 268 |
|
@@ -327,7 +341,8 @@ async def run_streaming_action(
|
327 | 341 | version: The Genkit version header value.
|
328 | 342 |
|
329 | 343 | Returns:
|
330 |
| - A StreamingResponse with JSON chunks or JSONResponse with error. |
| 344 | + A StreamingResponse with JSON chunks containing result or error |
| 345 | + events. |
331 | 346 | """
|
332 | 347 |
|
333 | 348 | async def sse_generator() -> AsyncGenerator[str, None]:
|
@@ -410,9 +425,10 @@ async def run_standard_action(
|
410 | 425 | return Starlette(
|
411 | 426 | routes=[
|
412 | 427 | Route('/api/__health', health_check, methods=['GET']),
|
| 428 | + Route('/api/__quitquitquit', terminate, methods=['POST']), |
413 | 429 | Route('/api/actions', list_actions, methods=['GET']),
|
414 |
| - Route('/api/runAction', run_action, methods=['POST']), |
415 | 430 | Route('/api/notify', handle_notify, methods=['POST']),
|
| 431 | + Route('/api/runAction', run_action, methods=['POST']), |
416 | 432 | ],
|
417 | 433 | middleware=[
|
418 | 434 | Middleware(
|
|
0 commit comments