Skip to content

Commit

Permalink
fix #10 - check vrt validity in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Dec 20, 2023
1 parent 695d4d1 commit cd94436
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 12 additions & 0 deletions metadata_catalogue/datasets/libs/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ def vrt():
check_definition(dt.content)
except:
logging.warn(f"{dt.fetch_url}{traceback.format_exception()}")


def validate_vrt(content_id):
Content = apps.get_model("datasets", "Content")
content = Content.objects.get(id=content_id)
try:
check_definition(content)
content.valid = True
except:
logging.error(f"VRT ERROR: {content.dataset_id} - {traceback.format_exc()}")
content.valid = False
content.save(update_fields=["valid"])
11 changes: 2 additions & 9 deletions metadata_catalogue/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from django_lifecycle import AFTER_CREATE, AFTER_DELETE, AFTER_SAVE, LifecycleModel, hook
from django_q.tasks import async_task
from solo.models import SingletonModel

from . import logger
from .libs.checks import check_definition
from .libs.iso.mapping import ISOMapping
from .managers import DatasetManager

Expand Down Expand Up @@ -405,13 +404,7 @@ class Content(LifecycleModel):

@hook(AFTER_SAVE, when_any=["gdal_vrt_definition"], has_changed=True)
def check_is_valid(self):
try:
check_definition(self)
self.valid = True
except:
logger.error(f"VRT ERROR: {self.dataset_id} - {traceback.format_exc()}")
self.valid = False
self.save(update_fields=["valid"])
async_task("metadata_catalogue.datasets.libs.checks.validate_vrt", self.id)

def __str__(self):
return str(self.dataset)

0 comments on commit cd94436

Please sign in to comment.