Skip to content

Commit

Permalink
Merge pull request #2042 from IFRCGo/fix/sync-appeal-docs-error-handling
Browse files Browse the repository at this point in the history
Check Country an AppealDocumentType for sync AppealDocs
  • Loading branch information
szabozoltan69 authored Jun 6, 2024
2 parents 5e7ea41 + db613c3 commit d9828fc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions api/management/commands/sync_appealdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from main.sentry import SentryMonitor
from sentry_sdk.crons import monitor
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from api.models import Appeal, AppealDocument, CronJob, CronJobStatus
from api.models import Appeal, AppealDocument, AppealDocumentType, CronJob, CronJobStatus
from api.logger import logger
from collections import defaultdict
from django.conf import settings

CRON_NAME = "sync_appealdocs"
Expand All @@ -34,6 +32,7 @@ def handle(self, *args, **options):
logger.info("Starting appeal document ingest")

if options["fullscan"]:
# FIXME: should be inserted to cron jobs, 4 monthly or so. Or create a calendar note for maintainer.
# If the `--fullscan` option is passed (at the end of command), check ALL appeals. Runs an hour!
print("Doing a full scan of all Appeals")
qset = Appeal.objects.all()
Expand Down Expand Up @@ -71,6 +70,16 @@ def handle(self, *args, **options):
existing.append(document_url)
else:
try:
iso = result["LocationCountryCode"]
if not iso:
iso = Appeal.objects.get(pk=appeal_id).country.iso
if not iso:
logger.warning("Wrong AppealDocument data – unknown country.")
continue
appealtype_id = result["AppealsTypeId"]
if not appealtype_id or not AppealDocumentType.objects.filter(id=appealtype_id): # not pk=...!
logger.warning("Wrong AppealDocument data – unknown type_id: %s", appealtype_id)
continue
created_at = None
if "AppealsDate" in result:
created_at = self.parse_date(result["AppealsDate"])
Expand All @@ -81,8 +90,8 @@ def handle(self, *args, **options):
appeal_id=appeal_id,
name=result["AppealsName"],
description=result["AppealOrigType"],
type_id=result["AppealsTypeId"],
iso_id=result["LocationCountryCode"],
type_id=appealtype_id,
iso_id=iso,
created_at=created_at
)
created.append(document_url)
Expand Down

0 comments on commit d9828fc

Please sign in to comment.