From a32996ccc3ce7dd69827eb11b6fcd9386d2dc536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 10 Nov 2024 23:39:03 +0100 Subject: [PATCH] Schedule tasks hourly --- games/apps.py | 11 ++++++----- games/management/commands/schedule_update_task.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/games/apps.py b/games/apps.py index 1a65502..cebaa41 100644 --- a/games/apps.py +++ b/games/apps.py @@ -2,8 +2,6 @@ from datetime import timedelta from django.apps import AppConfig from django.utils.timezone import now -from django_q.models import Schedule -from django_q.tasks import schedule class GamesConfig(AppConfig): @@ -11,10 +9,13 @@ class GamesConfig(AppConfig): name = "games" def ready(self): + from django_q.models import Schedule + from django_q.tasks import schedule + if not Schedule.objects.filter(name="Update converted prices").exists(): schedule( - "games.tasks.update_converted_prices", + "games.convert_price.update_converted_prices", name="Update converted prices", - schedule_type="D", - next_run=now() + timedelta(days=1), + schedule_type=Schedule.HOURLY, + next_run=now() + timedelta(seconds=30), ) diff --git a/games/management/commands/schedule_update_task.py b/games/management/commands/schedule_update_task.py index 4dd3096..6d40e78 100644 --- a/games/management/commands/schedule_update_task.py +++ b/games/management/commands/schedule_update_task.py @@ -12,10 +12,10 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): if not Schedule.objects.filter(name="Update converted prices").exists(): schedule( - "games.tasks.update_converted_prices", + "games.convert_price.update_converted_prices", name="Update converted prices", - schedule_type="D", - next_run=now() + timedelta(days=1), + schedule_type=Schedule.HOURLY, + next_run=now() + timedelta(seconds=30), ) self.stdout.write( self.style.SUCCESS("Scheduled the update_converted_prices task.")