handle media which may not have a published date set for some erroneous reason, related to #77
This commit is contained in:
parent
8525d920a0
commit
df9316bede
|
@ -19,6 +19,7 @@ class Command(BaseCommand):
|
|||
# Iter all tasks
|
||||
for source in Source.objects.all():
|
||||
# Recreate the initial indexing task
|
||||
log.info(f'Resetting tasks for source: {source}')
|
||||
verbose_name = _('Index media from source "{}"')
|
||||
index_source_task(
|
||||
str(source.pk),
|
||||
|
|
|
@ -100,6 +100,13 @@ def media_post_save(sender, instance, created, **kwargs):
|
|||
# already been downloaded
|
||||
if not instance.downloaded:
|
||||
max_cap_age = instance.source.download_cap_date
|
||||
published = instance.published
|
||||
if not published:
|
||||
log.warn(f'Media: {instance.source} / {instance} has no published date '
|
||||
f'set, marking to be skipped')
|
||||
instance.skip = True
|
||||
cap_changed = True
|
||||
else:
|
||||
if max_cap_age:
|
||||
if instance.published > max_cap_age and instance.skip:
|
||||
# Media was published after the cap date but is set to be skipped
|
||||
|
@ -108,8 +115,8 @@ def media_post_save(sender, instance, created, **kwargs):
|
|||
instance.skip = False
|
||||
cap_changed = True
|
||||
elif instance.published <= max_cap_age and not instance.skip:
|
||||
log.info(f'Media: {instance.source} / {instance} is too old for the '
|
||||
f'download cap date, marking to be skipped')
|
||||
log.info(f'Media: {instance.source} / {instance} is too old for '
|
||||
f'the download cap date, marking to be skipped')
|
||||
instance.skip = True
|
||||
cap_changed = True
|
||||
else:
|
||||
|
@ -119,6 +126,11 @@ def media_post_save(sender, instance, created, **kwargs):
|
|||
f'publishing date, marking to be unskipped')
|
||||
instance.skip = False
|
||||
cap_changed = True
|
||||
# Save the instance if any changes were required
|
||||
if cap_changed or can_download_changed:
|
||||
post_save.disconnect(media_post_save, sender=Media)
|
||||
instance.save()
|
||||
post_save.connect(media_post_save, sender=Media)
|
||||
# Recalculate the "can_download" flag, this may
|
||||
# need to change if the source specifications have been changed
|
||||
if instance.metadata:
|
||||
|
@ -130,11 +142,6 @@ def media_post_save(sender, instance, created, **kwargs):
|
|||
if instance.can_download:
|
||||
instance.can_download = False
|
||||
can_download_changed = True
|
||||
# Save the instance if any changes were required
|
||||
if cap_changed or can_download_changed:
|
||||
post_save.disconnect(media_post_save, sender=Media)
|
||||
instance.save()
|
||||
post_save.connect(media_post_save, sender=Media)
|
||||
# If the media is missing metadata schedule it to be downloaded
|
||||
if not instance.metadata:
|
||||
log.info(f'Scheduling task to download metadata for: {instance.url}')
|
||||
|
|
Loading…
Reference in New Issue