2024-11-10 14:34:08 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2022-12-31 13:18:27 +00:00
|
|
|
from django.apps import AppConfig
|
2024-11-10 23:38:23 +00:00
|
|
|
from django.core.management import call_command
|
|
|
|
from django.db.models.signals import post_migrate
|
2024-11-10 14:34:08 +00:00
|
|
|
from django.utils.timezone import now
|
2022-12-31 13:18:27 +00:00
|
|
|
|
|
|
|
|
2023-01-19 19:35:25 +00:00
|
|
|
class GamesConfig(AppConfig):
|
2022-12-31 13:18:27 +00:00
|
|
|
default_auto_field = "django.db.models.BigAutoField"
|
2023-01-19 19:35:25 +00:00
|
|
|
name = "games"
|
2024-11-10 14:34:08 +00:00
|
|
|
|
|
|
|
def ready(self):
|
2024-11-10 23:38:23 +00:00
|
|
|
post_migrate.connect(schedule_tasks, sender=self)
|
|
|
|
|
|
|
|
|
|
|
|
def schedule_tasks(sender, **kwargs):
|
|
|
|
from django_q.models import Schedule
|
|
|
|
from django_q.tasks import schedule
|
|
|
|
|
|
|
|
if not Schedule.objects.filter(name="Update converted prices").exists():
|
|
|
|
schedule(
|
|
|
|
"games.convert_price.update_converted_prices",
|
|
|
|
name="Update converted prices",
|
2024-11-10 23:47:48 +00:00
|
|
|
schedule_type=Schedule.MINUTES,
|
2024-11-10 23:38:23 +00:00
|
|
|
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")
|