mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 05:56:37 +00:00
commit
c434eb2487
@ -552,7 +552,7 @@ class Source(db.models.Model):
|
||||
entries.maxlen // 2,
|
||||
entries.maxlen - len(entries),
|
||||
)
|
||||
entries.extend(reversed(streams[-1 * allowed_streams :]))
|
||||
entries.extend(reversed(streams[: allowed_streams]))
|
||||
|
||||
return entries
|
||||
|
||||
|
@ -233,19 +233,33 @@ def schedule_media_servers_update():
|
||||
)
|
||||
|
||||
|
||||
def wait_for_errors(media, /, tn='sync.tasks.download_media_metadata'):
|
||||
def wait_for_errors(model, /, *, task_name=None):
|
||||
if task_name is None:
|
||||
task_name=tuple((
|
||||
'sync.tasks.download_media',
|
||||
'sync.tasks.download_media_metadata',
|
||||
))
|
||||
elif isinstance(task_name, str):
|
||||
task_name = tuple((task_name,))
|
||||
tasks = list()
|
||||
for tn in task_name:
|
||||
ft = get_first_task(tn, instance=model)
|
||||
if ft:
|
||||
tasks.append(ft)
|
||||
window = timezone.timedelta(hours=3) + timezone.now()
|
||||
tqs = Task.objects.filter(
|
||||
task_name=tn,
|
||||
task_name__in=task_name,
|
||||
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)')
|
||||
for task in tasks:
|
||||
update_task_status(task, 'paused (429)')
|
||||
log.info(f'waiting for errors: 429 ({tqs.count()}): {model}')
|
||||
time.sleep(10 * tqs.count())
|
||||
update_task_status(task, None)
|
||||
for task in tasks:
|
||||
update_task_status(task, None)
|
||||
|
||||
|
||||
def cleanup_old_media():
|
||||
@ -484,7 +498,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)
|
||||
wait_for_errors(media, task_name='sync.tasks.download_media_metadata')
|
||||
try:
|
||||
metadata = media.index_metadata()
|
||||
except YouTubeError as e:
|
||||
@ -637,6 +651,7 @@ def download_media(media_id, override=False):
|
||||
# should raise an exception to avoid this
|
||||
return
|
||||
|
||||
wait_for_errors(media, task_name='sync.tasks.download_media')
|
||||
filepath = media.filepath
|
||||
container = format_str = None
|
||||
log.info(f'Downloading media: {media} (UUID: {media.pk}) to: "{filepath}"')
|
||||
|
Loading…
Reference in New Issue
Block a user