diff --git a/rasa_sdk/constants.py b/rasa_sdk/constants.py index 73400cc1e..ad52aaeb1 100644 --- a/rasa_sdk/constants.py +++ b/rasa_sdk/constants.py @@ -1,5 +1,6 @@ DEFAULT_SERVER_PORT = 5055 DEFAULT_SANIC_WORKERS = 1 +DEFAULT_KEEP_ALIVE_TIMEOUT = 120 # in seconds ENV_SANIC_WORKERS = "ACTION_SERVER_SANIC_WORKERS" DEFAULT_LOG_LEVEL_LIBRARIES = "ERROR" ENV_LOG_LEVEL_LIBRARIES = "LOG_LEVEL_LIBRARIES" diff --git a/rasa_sdk/endpoint.py b/rasa_sdk/endpoint.py index 4c2a038f0..d923aa7d1 100644 --- a/rasa_sdk/endpoint.py +++ b/rasa_sdk/endpoint.py @@ -15,7 +15,7 @@ from rasa_sdk import utils from rasa_sdk.cli.arguments import add_endpoint_arguments -from rasa_sdk.constants import DEFAULT_SERVER_PORT +from rasa_sdk.constants import DEFAULT_KEEP_ALIVE_TIMEOUT, DEFAULT_SERVER_PORT from rasa_sdk.executor import ActionExecutor from rasa_sdk.interfaces import ActionExecutionRejection, ActionNotFoundException from rasa_sdk.plugin import plugin_manager @@ -160,6 +160,7 @@ def run( ssl_password: Optional[Text] = None, auto_reload: bool = False, tracer_provider: Optional[TracerProvider] = None, + keep_alive_timeout: int = DEFAULT_KEEP_ALIVE_TIMEOUT, ) -> None: """Starts the action endpoint server with given config values.""" logger.info("Starting action endpoint server...") @@ -169,6 +170,7 @@ def run( auto_reload=auto_reload, tracer_provider=tracer_provider, ) + app.config.KEEP_ALIVE_TIMEOUT = keep_alive_timeout ## Attach additional sanic extensions: listeners, middleware and routing logger.info("Starting plugins...") plugin_manager().hook.attach_sanic_app_extensions(app=app)