def wrapper(*args, **kwargs): backend = app.backend call_args = getcallargs(wrapped, *args, **kwargs) task_name = app.gen_task_name(wrapped.__name__, wrapped.__module__) key = queue_once_key(task_name, call_args) now = int(timezone.now().timestamp()) expiration_delay = settings.CELERY_MUTEX_TIMEOUT result = backend.get(key) if result: remaining = now - int(result) if remaining < 0: return backend.set(key, now + expiration_delay) try: return wrapped(*args, **kwargs) finally: backend.delete(key)
def test_queue_once_key_kwargs_restrict_keys(): key = queue_once_key("example", {'pk': 10, 'id': 10}, restrict_to=['pk']) assert key == "qo_example_pk-10"
def test_queue_once_key_kwargs(): key = queue_once_key("example", {'pk': 10}) assert key == "qo_example_pk-10"
def test_queue_once_key(): key = queue_once_key("example", {}) assert key == "qo_example"
def test_queue_once_key_unicode_py3(): key = queue_once_key(u"éxample", {'a': u'é', u'b': 'é'}) assert key == "qo_éxample_a-é_b-é"
def test_queue_once_key_unicode_py2(): key = queue_once_key(u"éxample", {'a': u'é', u'b': 'é'}) assert key == "qo_\xc3\xa9xample_a-\xc3\xa9_b-\xc3\xa9"
app.logger.warning("Error loading messages in database") # Log permissions try: if os.path.isdir("/var/log/alienvault/api"): for api_logfile in os.listdir("/var/log/alienvault/api"): os.chmod("/var/log/alienvault/api/%s" % api_logfile, 0644) except Exception as e: pass # Purge celery-once references from redis from celery_once.helpers import queue_once_key from celery_once.tasks import QueueOnce from db.methods.system import get_system_id_from_local system_id=get_system_id_from_local()[1] args={'system_id' : u'%s' % system_id} task_name = "celerymethods.tasks.backup_tasks.backup_configuration_for_system_id" key = queue_once_key(task_name, args, None) aux = QueueOnce() aux.clear_lock(key) # This is the recommended way of packaging a Flask app. # This seems to be a hack to avoid circulat imports. # See http://flask.pocoo.org/docs/patterns/packages/ import api.views # (Keep pyflakes quiet) views login_manager.login_view = "auth.login"
def get_celery_once_lock_key(name, args): return queue_once_key(name, OrderedDict(args), None)
app.logger.warning("Error loading messages in database") # Log permissions try: if os.path.isdir("/var/log/alienvault/api"): for api_logfile in os.listdir("/var/log/alienvault/api"): os.chmod("/var/log/alienvault/api/%s" % api_logfile, 0644) except Exception as e: pass # Purge celery-once references from redis from celery_once.helpers import queue_once_key from celery_once.tasks import QueueOnce from db.methods.system import get_system_id_from_local system_id = get_system_id_from_local()[1] args = {'system_id': u'%s' % system_id} task_name = "celerymethods.tasks.backup_tasks.backup_configuration_for_system_id" key = queue_once_key(task_name, args, None) aux = QueueOnce() aux.clear_lock(key) # This is the recommended way of packaging a Flask app. # This seems to be a hack to avoid circulat imports. # See http://flask.pocoo.org/docs/patterns/packages/ import api.views # (Keep pyflakes quiet) views login_manager.login_view = "auth.login"