Skip to content

Commit

Permalink
worker
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno committed Mar 9, 2024
1 parent cf02107 commit 7ffc106
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 0 additions & 2 deletions backend/pycon/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,3 @@
X_FRAME_OPTIONS = "SAMEORIGIN"

CELERY_TASK_IGNORE_RESULT = True

PYTEST_XDIST_WORKER = env("PYTEST_XDIST_WORKER", default="")
16 changes: 9 additions & 7 deletions backend/schedule/tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time
import threading

Expand Down Expand Up @@ -373,23 +374,25 @@ def upload_schedule_item_video(*, sent_for_video_upload_state_id: int):
def renew_lock(lock, interval):
while lock.locked:
try:
lock.extend(interval, replace_ttl=True)
extended = lock.extend(interval, replace_ttl=True)
except Exception as e:
logger.exception("Error renewing lock: %s", e)
break

if lock.locked:
if extended and lock.locked:
time.sleep(interval)


def lock_task(func):
# This is a dummy lock until we can get celery-heimdall
def wrapper(*args, **kwargs):
timeout = 60 * 5

lock_id = f"celery_lock_{func.__name__}"
PYTEST_XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER")

if settings.PYTEST_XDIST_WORKER:
lock_id = f"{lock_id}_{settings.PYTEST_XDIST_WORKER}"
if PYTEST_XDIST_WORKER:
lock_id = f"{lock_id}_{PYTEST_XDIST_WORKER}"

client = redis.Redis.from_url(settings.REDIS_URL)
lock = client.lock(lock_id, timeout=timeout, thread_local=False)
Expand All @@ -403,9 +406,8 @@ def wrapper(*args, **kwargs):
return func(*args, **kwargs)
finally:
lock.release()
renewer_thread.join()

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

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

View check run for this annotation

Codecov / codecov/patch

backend/schedule/tasks.py#L411-L412

Added lines #L411 - L412 were not covered by tests

Expand Down

0 comments on commit 7ffc106

Please sign in to comment.