do not get_config in global scope (#3597)

* do not get_config in global scope

* ruff fixes

* pydantic v1 compatibility
This commit is contained in:
benedikt-bartscher 2024-07-01 19:17:40 +02:00 committed by GitHub
parent f0bab665ce
commit b742afb27f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,7 +61,6 @@ if TYPE_CHECKING:
Delta = Dict[str, Any]
var = computed_var
config = get_config()
# If the state is this large, it's considered a performance issue.
@ -2319,6 +2318,24 @@ def _dill_reduce_state(pickler, obj):
dill.Pickler.dispatch[type](pickler, obj)
def _default_lock_expiration() -> int:
"""Get the default lock expiration time.
Returns:
The default lock expiration time.
"""
return get_config().redis_lock_expiration
def _default_token_expiration() -> int:
"""Get the default token expiration time.
Returns:
The default token expiration time.
"""
return get_config().redis_token_expiration
class StateManagerRedis(StateManager):
"""A state manager that stores states in redis."""
@ -2326,10 +2343,10 @@ class StateManagerRedis(StateManager):
redis: Redis
# The token expiration time (s).
token_expiration: int = config.redis_token_expiration
token_expiration: int = pydantic.Field(default_factory=_default_token_expiration)
# The maximum time to hold a lock (ms).
lock_expiration: int = config.redis_lock_expiration
lock_expiration: int = pydantic.Field(default_factory=_default_lock_expiration)
# The keyspace subscription string when redis is waiting for lock to be released
_redis_notify_keyspace_events: str = (