Skip to content

Commit

Permalink
[Hardening] make sure remote services handler ingests and updates the…
Browse files Browse the repository at this point in the history
… layer between the same transaction
  • Loading branch information
afabiani committed Nov 29, 2020
1 parent 668caf9 commit dfd8c91
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions geonode/services/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
#
#########################################################################
"""Celery tasks for geonode.services"""

import time
import logging

from django.db import IntegrityError, transaction

from . import models
from . import enumerations
from .serviceprocessors import get_service_handler
Expand Down Expand Up @@ -54,21 +52,24 @@ def harvest_resource(self, harvest_job_id):
result = False
details = ""
try:
with transaction.atomic():
handler = get_service_handler(
base_url=harvest_job.service.base_url,
proxy_base=harvest_job.service.proxy_base,
service_type=harvest_job.service.type
)
logger.debug("harvesting resource...")
handler.harvest_resource(
harvest_job.resource_id, harvest_job.service)
result = True
logger.debug("Resource harvested successfully")
layer = Layer.objects.get(alternate=harvest_job.resource_id)
layer.save(notify=True)
except IntegrityError:
raise
handler = get_service_handler(
base_url=harvest_job.service.base_url,
proxy_base=harvest_job.service.proxy_base,
service_type=harvest_job.service.type
)
logger.debug("harvesting resource...")
handler.harvest_resource(
harvest_job.resource_id, harvest_job.service)
logger.debug("Resource harvested successfully")
_cnt = 0
while _cnt < 5 and not result:
try:
layer = Layer.objects.get(alternate=harvest_job.resource_id)
layer.save(notify=True)
result = True
except Exception:
_cnt += 1
time.sleep(3)
except Exception as err:
logger.exception(msg="An error has occurred while harvesting "
"resource {!r}".format(harvest_job.resource_id))
Expand Down

0 comments on commit dfd8c91

Please sign in to comment.