From d05b53919ca1a6f9fbfbeda009eb1db941d07531 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 19 May 2025 11:17:39 -0400 Subject: [PATCH 1/3] Wait for HTTP 429 errors --- tubesync/sync/tasks.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 0467a4fd..ba9f0261 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -235,6 +235,21 @@ def schedule_media_servers_update(): ) +def wait_for_errors(media, /, tn='sync.tasks.download_media_metadata'): + window = timezone.timedelta(hours=3) + timezone.now() + tqs = Task.objects.filter( + task_name=tn, + attempts__gt=0, + locked_at__isnull=True, + run_at__lte=window, + last_error__contains='HTTPError 429: Too Many Requests', + ) + task = get_first_task(tn, instance=media) + update_task_status(task, 'paused (429)') + time.sleep(10 * tqs.count()) + update_task_status(task, None) + + def cleanup_old_media(): with atomic(): for source in qs_gen(Source.objects.filter(delete_old_media=True, days_to_keep__gt=0)): @@ -467,6 +482,7 @@ def download_media_metadata(media_id): log.info(f'Task for ID: {media_id} / {media} skipped, due to task being manually skipped.') return source = media.source + wait_for_errors(media) try: metadata = media.index_metadata() except YouTubeError as e: From 1be1e583e56ac16ca3bb18661cadec1276181580 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 19 May 2025 11:32:56 -0400 Subject: [PATCH 2/3] Use `hasattr` for `update_task_status` --- tubesync/sync/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index ba9f0261..2942f37e 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -122,7 +122,7 @@ def get_error_message(task): def update_task_status(task, status): if not task: return False - if not task._verbose_name: + if not hasattr(task, '_verbose_name'): task._verbose_name = remove_enclosed( task.verbose_name, '[', ']', ' ', ) From 8080f690769d50816af6aad66adb2d5c0bbf7ae9 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 19 May 2025 11:47:52 -0400 Subject: [PATCH 3/3] Remove an unnecessary condition --- tubesync/sync/tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index 2942f37e..8b39434b 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -848,8 +848,7 @@ def wait_for_media_premiere(media_id): if hours: task = get_media_premiere_task(media_id) - if task: - update_task_status(task, f'available in {hours} hours') + update_task_status(task, f'available in {hours} hours') save_model(media)