Skip to content

Commit

Permalink
Fix bits that were incorrectly merged when rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Garcia Silva committed Oct 19, 2021
1 parent a9e112a commit 6d47621
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions geonode/harvesting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class HarvestableResource(models.Model):
status = models.CharField(
max_length=50, choices=STATUS_CHOICES, default=STATUS_READY)
title = models.CharField(max_length=255)
abstract = models.TextField(max_length=2000, blank=True)
harvester = models.ForeignKey(
Harvester,
on_delete=models.CASCADE,
Expand Down
60 changes: 27 additions & 33 deletions geonode/harvesting/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,35 @@ def harvesting_scheduler(self):
"""

logger.debug("+++++ harvesting_dispatcher starting... +++++")
for harvester in models.Harvester.objects.all():
logger.debug(f"Checking harvester {harvester!r}...")
should_check_availability = _is_due(
harvester.check_availability_frequency,
harvester.last_checked_availability
)
logger.debug(f"- should_check_availability: {should_check_availability!r}")
if should_check_availability:
harvester.update_availability()
if harvester.is_availability_check_due():
logger.debug(f"{harvester.name} - Updating availability...")
available = harvester.update_availability()
logger.debug(f"{harvester.name} - is {'not ' if not available else ''}available")
else:
logger.debug(f"{harvester.name} - No need to update availability yet")
if harvester.scheduling_enabled:
logger.debug(f"- scheduling_enabled: {harvester.scheduling_enabled!r}")
should_refresh_harvestable_resources = _is_due(
harvester.refresh_harvestable_resources_update_frequency,
harvester.latest_refresh_session.started
)
logger.debug(f"- should_refresh_harvestable_resources: {should_refresh_harvestable_resources!r}")
if should_refresh_harvestable_resources:
harvester.initiate_update_harvestable_resources()
should_perform_harvesting = _is_due(
harvester.harvesting_session_update_frequency,
harvester.latest_harvesting_session.started
)
logger.debug(f"- should_perform_harvesting: {should_perform_harvesting!r}")
if should_perform_harvesting:
harvester.initiate_perform_harvesting()
logger.debug(f"{harvester.name} - scheduling_enabled: {harvester.scheduling_enabled!r}")
if harvester.is_harvestable_resources_refresh_due():
logger.debug(f"{harvester.name} - Initiating update of harvestable resources...")
try:
harvester.initiate_update_harvestable_resources()
except RuntimeError:
logger.exception(msg=f"{harvester.name} - Could not initiate the update of harvestable resources")
else:
logger.debug(f"{harvester.name} - No need to update harvestable resources yet")
if harvester.is_harvesting_due():
logger.debug(f"{harvester.name} - initiating harvesting...")
try:
harvester.initiate_perform_harvesting()
except RuntimeError:
logger.exception(msg=f"{harvester.name} - Could not initiate harvesting")
else:
logger.debug(f"{harvester.name} - No need to harvest yet")
else:
logger.debug(f"{harvester.name} - Scheduling is disabled for this harvester, skipping...")
logger.debug("+++++ harvesting_dispatcher ending... +++++")


@app.task(
Expand Down Expand Up @@ -704,13 +708,3 @@ def update_asynchronous_session(
if additional_details is not None:
update_kwargs["details"] = Concat("details", Value(f"\n{additional_details}"))
models.AsynchronousHarvestingSession.objects.filter(id=session_id).update(**update_kwargs)


def _is_due(frequency: int, last_check: typing.Optional[dt.datetime] = None):
try:
due_date = last_check + dt.timedelta(minutes=frequency)
except TypeError:
result = True
else:
result = due_date < timezone.now()
return result

0 comments on commit 6d47621

Please sign in to comment.