Skip to content

Commit

Permalink
dummy lock
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno committed Mar 9, 2024
1 parent 2e9c94c commit 2c547bb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backend/schedule/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.conf import settings
import logging
from integrations import slack

from django.core.cache import cache
from pycon.celery import app
from schedule.models import ScheduleItemSentForVideoUpload
from schedule.video_upload import (
Expand Down Expand Up @@ -367,7 +367,26 @@ def upload_schedule_item_video(*, sent_for_video_upload_state_id: int):
sent_for_video_upload.save(update_fields=["status"])


def lock_task(func):
# This is a dummy lock until we can get celery-heimdall
def wrapper(*args, **kwargs):
lock_id = f"celery_lock_{func.__name__}"
lock = cache.add(lock_id, "locked", timeout=60 * 60 * 1)

if not lock:
logger.info("Task %s is already running, skipping", func.__name__)
return

Check warning on line 378 in backend/schedule/tasks.py

View check run for this annotation

Codecov / codecov/patch

backend/schedule/tasks.py#L377-L378

Added lines #L377 - L378 were not covered by tests

try:
return func(*args, **kwargs)
finally:
cache.delete(lock_id)

return wrapper


@app.task()
@lock_task
def process_schedule_items_videos_to_upload():
statuses = (
ScheduleItemSentForVideoUpload.objects.filter(
Expand Down

0 comments on commit 2c547bb

Please sign in to comment.