Improve startup setup and tasks

This commit is contained in:
Lukáš Kucharczyk 2024-11-11 00:38:23 +01:00
parent 4fd5b8432b
commit b05a0bd502
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 21 additions and 9 deletions

View File

@ -1,6 +1,8 @@
from datetime import timedelta
from django.apps import AppConfig
from django.core.management import call_command
from django.db.models.signals import post_migrate
from django.utils.timezone import now
@ -9,6 +11,10 @@ class GamesConfig(AppConfig):
name = "games"
def ready(self):
post_migrate.connect(schedule_tasks, sender=self)
def schedule_tasks(sender, **kwargs):
from django_q.models import Schedule
from django_q.tasks import schedule
@ -19,3 +25,9 @@ class GamesConfig(AppConfig):
schedule_type=Schedule.HOURLY,
next_run=now() + timedelta(seconds=30),
)
from games.models import ExchangeRate
if not ExchangeRate.objects.exists():
print("ExchangeRate table is empty. Loading fixture...")
call_command("loaddata", "exchangerates.yaml")