From 983679964b4a56f560aeff8441dd996fba3a7413 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 16 Jun 2025 22:19:42 -0400 Subject: [PATCH] Abort `wait_for_errors` during container shutdown --- tubesync/sync/tasks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tubesync/sync/tasks.py b/tubesync/sync/tasks.py index adf5db71..3e3866d8 100644 --- a/tubesync/sync/tasks.py +++ b/tubesync/sync/tasks.py @@ -270,9 +270,19 @@ def wait_for_errors(model, /, *, queue_name=None, task_name=None): delay = 10 * total_count time_str = seconds_to_timestr(delay) log.info(f'waiting for errors: 429 ({time_str}): {model}') - time.sleep(delay) + db_down_path = Path('/run/service/tubesync-db-worker/down') + fs_down_path = Path('/run/service/tubesync-fs-worker/down') + while delay > 0: + # this happenes when the container is shutting down + # do not prevent that while we are delaying a task + if db_down_path.exists() and fs_down_path.exists(): + break + time.sleep(5) + delay -= 5 for task in tasks: update_task_status(task, None) + if delay > 0: + raise BgTaskWorkerError(_('queue worker stopped')) @db_task(queue=Val(TaskQueue.FS))