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
|
# Iter all tasks
|
||||||
for source in Source.objects.all():
|
for source in Source.objects.all():
|
||||||
# Recreate the initial indexing task
|
# Recreate the initial indexing task
|
||||||
|
log.info(f'Resetting tasks for source: {source}')
|
||||||
verbose_name = _('Index media from source "{}"')
|
verbose_name = _('Index media from source "{}"')
|
||||||
index_source_task(
|
index_source_task(
|
||||||
str(source.pk),
|
str(source.pk),
|
||||||
|
|
|
@ -100,6 +100,13 @@ def media_post_save(sender, instance, created, **kwargs):
|
||||||
# already been downloaded
|
# already been downloaded
|
||||||
if not instance.downloaded:
|
if not instance.downloaded:
|
||||||
max_cap_age = instance.source.download_cap_date
|
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 max_cap_age:
|
||||||
if instance.published > max_cap_age and instance.skip:
|
if instance.published > max_cap_age and instance.skip:
|
||||||
# Media was published after the cap date but is set to be skipped
|
# 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
|
instance.skip = False
|
||||||
cap_changed = True
|
cap_changed = True
|
||||||
elif instance.published <= max_cap_age and not instance.skip:
|
elif instance.published <= max_cap_age and not instance.skip:
|
||||||
log.info(f'Media: {instance.source} / {instance} is too old for the '
|
log.info(f'Media: {instance.source} / {instance} is too old for '
|
||||||
f'download cap date, marking to be skipped')
|
f'the download cap date, marking to be skipped')
|
||||||
instance.skip = True
|
instance.skip = True
|
||||||
cap_changed = True
|
cap_changed = True
|
||||||
else:
|
else:
|
||||||
|
@ -119,6 +126,11 @@ def media_post_save(sender, instance, created, **kwargs):
|
||||||
f'publishing date, marking to be unskipped')
|
f'publishing date, marking to be unskipped')
|
||||||
instance.skip = False
|
instance.skip = False
|
||||||
cap_changed = True
|
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
|
# Recalculate the "can_download" flag, this may
|
||||||
# need to change if the source specifications have been changed
|
# need to change if the source specifications have been changed
|
||||||
if instance.metadata:
|
if instance.metadata:
|
||||||
|
@ -130,11 +142,6 @@ def media_post_save(sender, instance, created, **kwargs):
|
||||||
if instance.can_download:
|
if instance.can_download:
|
||||||
instance.can_download = False
|
instance.can_download = False
|
||||||
can_download_changed = True
|
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 the media is missing metadata schedule it to be downloaded
|
||||||
if not instance.metadata:
|
if not instance.metadata:
|
||||||
log.info(f'Scheduling task to download metadata for: {instance.url}')
|
log.info(f'Scheduling task to download metadata for: {instance.url}')
|
||||||
|
|
Loading…
Reference in New Issue