Skip to content

Commit

Permalink
- Just making the tasks initialization coherent with the other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Oct 15, 2021
1 parent a1c4c20 commit 2a34de5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions geonode/harvesting/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,43 @@
from django.apps import AppConfig
from django.conf import settings
from django.conf.urls import url, include
from django.db.models.signals import post_migrate

from . import config


def run_setup_hooks(sender, **kwargs):
from django.utils import timezone

# Initialize periodic tasks
if 'django_celery_beat' in settings.INSTALLED_APPS and \
getattr(settings, 'CELERY_BEAT_SCHEDULER', None) == 'django_celery_beat.schedulers:DatabaseScheduler':
from django_celery_beat.models import (
IntervalSchedule,
PeriodicTask,
)

secs = config.get_setting("HARVESTER_SCHEDULER_FREQUENCY_MINUTES") * 60
check_intervals = IntervalSchedule.objects.filter(every=secs, period="seconds")
if not check_intervals.exists():
check_interval, _ = IntervalSchedule.objects.get_or_create(
every=secs,
period="seconds"
)
else:
check_interval = check_intervals.first()

PeriodicTask.objects.update_or_create(
name="harvesting-scheduler",
defaults=dict(
task="geonode.harvesting.tasks.harvesting_scheduler",
interval=check_interval,
args='',
start_time=timezone.now()
)
)


class HarvestingAppConfig(AppConfig):

name = "geonode.harvesting"
Expand All @@ -34,6 +67,7 @@ def ready(self):
urlpatterns += [
url(r'^api/v2/', include('geonode.harvesting.api.urls'))
]
post_migrate.connect(run_setup_hooks, sender=self)
settings.CELERY_BEAT_SCHEDULE['harvesting-scheduler'] = {
"task": "geonode.harvesting.tasks.harvesting_scheduler",
"schedule": config.get_setting("HARVESTER_SCHEDULER_FREQUENCY_MINUTES") * 60,
Expand Down

0 comments on commit 2a34de5

Please sign in to comment.