Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integra task simultaneous execution prevention lock #644

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/utils/redis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from functools import wraps

from django.core.cache import cache


def skip_locked(lock_name):
lock = cache.lock(lock_name)

def decorator(method):
@wraps(method)
def wrapper(*args, **kwargs):
if not lock.acquire(blocking=False):
return None
try:
return method(*args, **kwargs)
finally:
lock.release()
return wrapper
return decorator
2 changes: 2 additions & 0 deletions lib/integra/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from celery.utils.log import get_task_logger
from django.conf import settings

from core.utils.redis import skip_locked
from .utils import Loader, Updater

LOGGER = get_task_logger(__name__)
Expand Down Expand Up @@ -40,6 +41,7 @@ def run(self):


@shared_task
@skip_locked('integra_task')
def download_updates():
processed, updated, errors = 0, 0, 0
configs = getattr(settings, 'INTEGRA_CONFIGS', None)
Expand Down