Improve startup setup and tasks
This commit is contained in:
parent
4fd5b8432b
commit
b05a0bd502
|
@ -1,6 +1,8 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.apps import AppConfig
|
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
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,13 +11,23 @@ class GamesConfig(AppConfig):
|
||||||
name = "games"
|
name = "games"
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
from django_q.models import Schedule
|
post_migrate.connect(schedule_tasks, sender=self)
|
||||||
from django_q.tasks import schedule
|
|
||||||
|
|
||||||
if not Schedule.objects.filter(name="Update converted prices").exists():
|
|
||||||
schedule(
|
def schedule_tasks(sender, **kwargs):
|
||||||
"games.convert_price.update_converted_prices",
|
from django_q.models import Schedule
|
||||||
name="Update converted prices",
|
from django_q.tasks import schedule
|
||||||
schedule_type=Schedule.HOURLY,
|
|
||||||
next_run=now() + timedelta(seconds=30),
|
if not Schedule.objects.filter(name="Update converted prices").exists():
|
||||||
)
|
schedule(
|
||||||
|
"games.convert_price.update_converted_prices",
|
||||||
|
name="Update converted prices",
|
||||||
|
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")
|
||||||
|
|
Loading…
Reference in New Issue