| ⬅️ Back | 🏠Docs Root |
This module defines common dependencies and their initialization/cleanup functions for all ARQ worker modules. It centralizes the setup of shared resources like the Redis client and site settings manager, making them available in the worker’s context.
init_common_dependencies Functionasync def init_common_dependencies(ctx: dict, settings: WorkerSettings) -> None:
An asynchronous function responsible for initializing common dependencies required by ARQ workers. This function is typically called during the worker’s startup phase.
ctx (dict): The ARQ worker’s context dictionary, where initialized dependencies will be stored.settings (WorkerSettings): An instance of WorkerSettings containing application configurations.Process:
settings.redis_url, configured to decode responses as UTF-8 strings. The client is stored in ctx["redis_client"].RedisService with the created Redis client. The service is stored in ctx["redis_service"].SiteSettingsManager with the RedisService and WorkerSettings.site_settings_manager.get_settings_obj() and stores it in ctx["site_settings"].Raises:
Exception: If any error occurs during the initialization of dependencies.
close_common_dependencies Functionasync def close_common_dependencies(ctx: dict, settings: WorkerSettings) -> None:
An asynchronous function responsible for cleaning up common resources initialized by init_common_dependencies. This function is typically called during the worker’s shutdown phase.
ctx (dict): The ARQ worker’s context dictionary.settings (WorkerSettings): An instance of WorkerSettings (included for type consistency, though not directly used in this function).Process:
redis_client from the ctx. If present, it closes the Redis connection.