Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tubesync/common/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ def reschedule(self, task_id, eta):
self.enqueue(t)
return True

def scheduled_at_from_task(self, task_obj, /):
scheduled_at = None
if not (hasattr(task_obj, 'eta') and task_obj.eta):
return None
if self.utc:
scheduled_at = task_obj.eta.replace(tzinfo=datetime.timezone.utc)
else: # this path is unlikely
scheduled_at = timestamp_to_datetime(
datetime_to_timestamp(task_obj.eta, integer=False),
).astimezone(tz=datetime.timezone.utc)
return scheduled_at


def CancelExecution_init(self, *args, retry=None, **kwargs):
self.retry = retry
Expand Down Expand Up @@ -378,6 +390,9 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None):
th.failed_at = signal_dt
th.last_error = str(exception_obj)
elif signal_name == signals.SIGNAL_ENQUEUED:
scheduled_at = huey.scheduled_at_from_task(task_obj)
if scheduled_at:
th.scheduled_at = scheduled_at
from sync.models import Media, Source
if not th.verbose_name and task_obj.args:
key = task_obj.args[0]
Expand All @@ -392,12 +407,9 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None):
if hasattr(model_instance, 'name'):
th.verbose_name += f' / {model_instance.name}'
elif signal_name == signals.SIGNAL_SCHEDULED:
if huey.utc:
th.scheduled_at = task_obj.eta.replace(tzinfo=datetime.UTC)
else: # this path is unlikely
th.scheduled_at = timestamp_to_datetime(
datetime_to_timestamp(task_obj.eta, integer=False),
).astimezone(tz=datetime.UTC)
scheduled_at = huey.scheduled_at_from_task(task_obj)
if scheduled_at:
th.scheduled_at = scheduled_at
th.end_at = signal_dt
th.elapsed = history['elapsed']
th.save()
Expand Down
7 changes: 6 additions & 1 deletion tubesync/sync/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def test_media(self):
}]
}
'''
before_dt = timezone.now()
past_date = timezone.make_aware(datetime(year=2000, month=1, day=1))
test_media1 = Media.objects.create(
key='mediakey1',
Expand All @@ -419,7 +420,11 @@ def test_media(self):
test_media3_pk = str(test_media3.pk)
# simulate the tasks consumer signals having already run
now_dt = timezone.now()
TaskHistory.objects.all().update(start_at=now_dt, end_at=now_dt)
TaskHistory.objects.all().update(
scheduled_at=before_dt,
start_at=now_dt,
end_at=now_dt,
)
# Check the tasks to fetch the media thumbnails have been scheduled
found_download_task1 = get_media_download_task(test_media1_pk)
found_download_task2 = get_media_download_task(test_media2_pk)
Expand Down