fix: improve max active requests calculation logic

- Use app model's max_active_requests or fall back to global config
- When global APP_MAX_ACTIVE_REQUESTS is non-zero, enforce it as a hard limit
- Add comprehensive docstring explaining the behavior

Signed-off-by: -LAN- <laipz8200@outlook.com>
pull/22847/head
-LAN- 7 months ago
parent 882f8bdd2c
commit 4c1c2cb90c
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF

@ -130,9 +130,22 @@ class AppGenerateService:
@staticmethod @staticmethod
def _get_max_active_requests(app_model: App) -> int: def _get_max_active_requests(app_model: App) -> int:
max_active_requests = app_model.max_active_requests """
if max_active_requests is None: Get the maximum number of active requests allowed for an app.
max_active_requests = int(dify_config.APP_MAX_ACTIVE_REQUESTS)
If the app has a custom max_active_requests setting, it will be used
unless the global APP_MAX_ACTIVE_REQUESTS config is non-zero, in which
case the minimum of the two values is returned to enforce the global limit.
Args:
app_model: The App model instance
Returns:
The maximum number of active requests allowed
"""
max_active_requests = app_model.max_active_requests or dify_config.APP_MAX_ACTIVE_REQUESTS
if dify_config.APP_MAX_ACTIVE_REQUESTS != 0:
return min(max_active_requests, dify_config.APP_MAX_ACTIVE_REQUESTS)
return max_active_requests return max_active_requests
@classmethod @classmethod

Loading…
Cancel
Save