<s> import logging <EOL> from django . conf import settings <EOL> from django . core import signals <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> try : <EOL> import importlib <EOL> except ImportError : <EOL> import django . utils . importlib as importlib <EOL> try : <EOL> from . tasks import refresh_cache as celery_refresh_cache <EOL> except ImportError : <EOL> celery_refresh_cache = None <EOL> try : <EOL> from . rq_tasks import refresh_cache as rq_refresh_cache <EOL> except ImportError as exc : <EOL> rq_refresh_cache = None <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def get_cache ( backend , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from django . core . cache import _create_cache <EOL> except ImportError : <EOL> from django . core . cache import get_cache as _get_cache <EOL> return _get_cache ( backend , ** kwargs ) <EOL> cache = _create_cache ( backend , ** kwargs ) <EOL> if hasattr ( cache , '<STR_LIT>' ) : <EOL> signals . request_finished . connect ( cache . close ) <EOL> return cache <EOL> def get_job_class ( klass_str ) : <EOL> """<STR_LIT>""" <EOL> mod_name , klass_name = klass_str . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> try : <EOL> mod = importlib . import_module ( mod_name ) <EOL> except ImportError as e : <EOL> logger . error ( "<STR_LIT>" , mod_name , e ) <EOL> return <EOL> try : <EOL> klass = getattr ( mod , klass_name ) <EOL> except AttributeError : <EOL> logger . error ( "<STR_LIT>" , mod_name , klass_name ) <EOL> return <EOL> return klass <EOL> def enqueue_task ( * args , ** kwargs ) : <EOL> task_queue = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if task_queue == '<STR_LIT>' and rq_refresh_cache is not None : <EOL> return rq_refresh_cache . delay ( ** kwargs [ '<STR_LIT>' ] ) <EOL> elif task_queue == '<STR_LIT>' and celery_refresh_cache is not None : <EOL> return celery_refresh_cache . apply_async ( * args , ** kwargs ) <EOL> raise ImproperlyConfigured ( '<STR_LIT>' . format ( task_queue ) ) </s>
