<s> """<STR_LIT>""" <EOL> from functools import wraps <EOL> from django . core . cache import cache <EOL> SEED_CACHE_PREFIX = '<STR_LIT>' <EOL> LOCK_CACHE_PREFIX = SEED_CACHE_PREFIX + '<STR_LIT>' <EOL> PROGRESS_CACHE_PREFIX = SEED_CACHE_PREFIX + '<STR_LIT>' <EOL> def _get_cache_key ( prefix , import_file_pk ) : <EOL> """<STR_LIT>""" <EOL> return unicode ( cache . make_key ( <EOL> '<STR_LIT>' . format ( prefix , import_file_pk ) <EOL> ) ) <EOL> def _get_lock_key ( func_name , import_file_pk ) : <EOL> return _get_cache_key ( LOCK_CACHE_PREFIX . format ( func_name ) , import_file_pk ) <EOL> def get_prog_key ( func_name , import_file_pk ) : <EOL> return _get_cache_key ( <EOL> PROGRESS_CACHE_PREFIX . format ( func_name ) , import_file_pk <EOL> ) <EOL> def increment_cache ( key , increment ) : <EOL> """<STR_LIT>""" <EOL> value = cache . get ( key ) or <NUM_LIT:0.0> <EOL> value = float ( value ) <EOL> if value + increment >= <NUM_LIT> : <EOL> value = <NUM_LIT> <EOL> else : <EOL> value += increment <EOL> cache . set ( key , value ) <EOL> def lock_and_track ( fn , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> func_name = fn . __name__ <EOL> @ wraps ( fn ) <EOL> def _wrapped ( import_file_pk , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> lock_key = _get_lock_key ( func_name , import_file_pk ) <EOL> prog_key = get_prog_key ( func_name , import_file_pk ) <EOL> is_locked = cache . get ( lock_key ) <EOL> if is_locked : <EOL> return { '<STR_LIT:error>' : '<STR_LIT>' } <EOL> cache . set ( lock_key , <NUM_LIT:1> , <NUM_LIT> ) <EOL> try : <EOL> response = fn ( import_file_pk , * args , ** kwargs ) <EOL> finally : <EOL> cache . set ( lock_key , <NUM_LIT:0> ) <EOL> if isinstance ( response , dict ) : <EOL> response [ '<STR_LIT>' ] = prog_key <EOL> return response <EOL> return _wrapped </s>
