:py:mod:`EVECelery.tasks.BaseTasks.TaskCached` ============================================== .. py:module:: EVECelery.tasks.BaseTasks.TaskCached Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: EVECelery.tasks.BaseTasks.TaskCached.TaskCached .. py:class:: TaskCached Bases: :py:obj:`EVECelery.tasks.BaseTasks.TaskBase.TaskBase` A task utilizing Redis for some form of caching and locks where the results are cached. .. py:property:: redis_locks :type: redis.Redis Get the Redis client for managing the locks .. py:property:: redis_cache :type: redis.Redis Get the Redis client for managing the cache .. py:method:: default_ttl() -> int Default TTL to set in Redis for results that don't have expiry information. :return: The number of seconds to cache a response .. py:method:: reflection_get_model(model_name: str) :classmethod: Lookup a pydantic model in the current module by its string name. Resolves a pydantic model existing or imported by the current module by its name. :param model_name: The class name to lookup .. py:method:: get_hash(**kwargs) -> str Returns the SHA256 hash of kwargs .. py:method:: get_redis_cache_key(**kwargs) -> str Returns the Redis key for storing a cached response with the provided input parameters. :param kwargs: Parameters passed to the task :return: Redis key for storing the value of the ESI response :rtype: str .. py:method:: get_redis_lock_key(**kwargs) -> str Returns the Redis key for lock response with the provided input parameters. :param kwargs: ESI request parameters :return: Redis key for storing ESI locks :rtype: str .. py:method:: cache_key_exists(**kwargs) -> bool Check if cache key exists for given input .. py:method:: get_sync(kwargs_apply_async: Optional[dict] = None, kwargs_get: Optional[dict] = None, **kwargs) -> EVECelery.tasks.BaseTasks.Models.ModelsCached.ModelCachedResponse Call this task and block until the result is available. Calls this celery task with additional helper functionality specific for EVECelery (deserialization to pydantic models support and result backend resource cleanup). This function is a wrapper around Celery's `task.apply_async() `_ and `AsyncResult.get() `_ methods. :param Optional[dict] kwargs_apply_async: Dictionary of keyword arguments passed to `task.apply_async() `_ :param Optional[dict] kwargs_get: Dictionary of keyword arguments passed to `AsyncResult.get() `_ :param **kwargs: Keyword arguments passed to this task's :func:`~run` method. :return: Result of a task :examples: >>> TaskBase.get_sync(kwargs_get={'timeout': 5}) # equivalent to BaseTask.apply_async().get(timeout=5) >>> r = TaskBase.get_sync() # equivalent to BaseTask.apply_async().get() >>> r = TaskBase.get_sync(lookup_id=5) # equivalent to BaseTask.apply_async(kwargs={'lookup_id': 5}).get() .. py:method:: run(**kwargs) -> dict Returns the result from the Redis cache if it exists, otherwise runs and returns :func:`_run_get_result` as a dictionary. This function checks the cache based on the provided input and will return the result from the cache first, skipping a rerun of :func:`_run_get_result`. If the result does not exist in the cache it will run :func:`_run_get_result` and cache the result for future task runs. If an exception is raised by :func:`_run_get_result` the exception will be raised to the calling client and will not be cached. If :func:`_run_get_result` returns a :func:`ModelCachedException` then the exception will first be cached and then thrown to the calling client as a :func:`CachedException`. :return: The response data as a dictionary. This dictionary can be converted to a pydantic model by passing it to this task's :func:`to_pydantic` method for easier inspection and schema documentation (required fields, field meanings, etc.). .. py:method:: _run_get_result(**kwargs) -> Union[EVECelery.tasks.BaseTasks.Models.ModelsCached.ModelCachedResponse, EVECelery.tasks.BaseTasks.Models.ModelsCached.ModelCachedException] :abstractmethod: The task body to execute if the result is not currently cached. This function is the body of a task that gets executed when a previously returned result is not cached or has expired. This function must return a pydantic model that inherits from :func:`ModelCachedResponse` or :func:`ModelCachedException`. If :func:`ModelCachedException` is returned, then the exception will be cached for the defined TTL and have an exception thrown to the calling client. :return: The response success or cached exception pydantic model.