__init__.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. from contextvars import ContextVar
  2. from threading import Lock
  3. from typing import TYPE_CHECKING
  4. from contexts.wrapper import RecyclableContextVar
  5. if TYPE_CHECKING:
  6. from core.plugin.entities.plugin_daemon import PluginModelProviderEntity
  7. from core.tools.plugin_tool.provider import PluginToolProviderController
  8. from core.workflow.entities.variable_pool import VariablePool
  9. tenant_id: ContextVar[str] = ContextVar("tenant_id")
  10. workflow_variable_pool: ContextVar["VariablePool"] = ContextVar("workflow_variable_pool")
  11. """
  12. To avoid race-conditions caused by gunicorn thread recycling, using RecyclableContextVar to replace with
  13. """
  14. plugin_tool_providers: RecyclableContextVar[dict[str, "PluginToolProviderController"]] = RecyclableContextVar(
  15. ContextVar("plugin_tool_providers")
  16. )
  17. plugin_tool_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_tool_providers_lock"))
  18. plugin_model_providers: RecyclableContextVar[list["PluginModelProviderEntity"] | None] = RecyclableContextVar(
  19. ContextVar("plugin_model_providers")
  20. )
  21. plugin_model_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  22. ContextVar("plugin_model_providers_lock")
  23. )