Skip to content

Commit

Permalink
Merge pull request #665 from tcely/patch-6
Browse files Browse the repository at this point in the history
Do not delete tasks that are currently running
  • Loading branch information
meeb authored Feb 5, 2025
2 parents 690cb42 + 583863c commit 26940c8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tubesync/sync/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,18 @@ def get_media_premiere_task(media_id):
return False

def delete_task_by_source(task_name, source_id):
return Task.objects.filter(task_name=task_name, queue=str(source_id)).delete()
now = timezone.now()
unlocked = Task.objects.unlocked(now)
return unlocked.filter(task_name=task_name, queue=str(source_id)).delete()


def delete_task_by_media(task_name, args):
return Task.objects.drop_task(task_name, args=args)
max_run_time = getattr(settings, 'MAX_RUN_TIME', 3600)
now = timezone.now()
expires_at = now - timedelta(seconds=max_run_time)
task_qs = Task.objects.get_task(task_name, args=args)
unlocked = task_qs.filter(locked_by=None) | task_qs.filter(locked_at__lt=expires_at)
return unlocked.delete()


def cleanup_completed_tasks():
Expand Down

0 comments on commit 26940c8

Please sign in to comment.