Add more interval choices

This commit is contained in:
2023-03-11 17:43:10 +00:00
parent 5f0c555aa3
commit 8dc1e83d0a
3 changed files with 52 additions and 7 deletions

View File

@@ -4,16 +4,18 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
from django.core.management.base import BaseCommand
from core.clients.aggregators.nordigen import NordigenClient
from core.models import Aggregator
from core.clients.platforms.agora import AgoraClient
from core.models import INTERVAL_CHOICES, Aggregator, Platform
from core.util import logs
log = logs.get_logger("scheduling")
INTERVAL = 5
INTERVAL_AGGREGATOR = 5
INTERVALS_PLATFORM = [x[0] for x in INTERVAL_CHOICES]
async def job():
print("Running schedule.")
async def aggregator_job():
aggregators = Aggregator.objects.filter(enabled=True, fetch_accounts=True)
for aggregator in aggregators:
if aggregator.service == "nordigen":
@@ -25,6 +27,20 @@ async def job():
aggregator.save()
async def platform_job(interval):
print("PLATFORM JOB FOR", interval)
if interval == 0:
return
platforms = Platform.objects.filter(enabled=True, cheat_interval_seconds=interval)
for platform in platforms:
if platform.service == "agora":
if platform.cheat is True:
instance = await AgoraClient(platform)
await instance.cheat()
else:
raise NotImplementedError(f"No such client library: {platform.service}")
class Command(BaseCommand):
def handle(self, *args, **options):
"""
@@ -32,8 +48,15 @@ class Command(BaseCommand):
"""
scheduler = AsyncIOScheduler()
log.debug(f"Scheduling checking process job every {INTERVAL} seconds")
scheduler.add_job(job, "interval", seconds=INTERVAL)
log.debug(f"Scheduling {INTERVAL_AGGREGATOR} second aggregator job")
scheduler.add_job(aggregator_job, "interval", seconds=INTERVAL_AGGREGATOR)
for interval in INTERVALS_PLATFORM:
if interval == 0:
continue
log.debug(f"Scheduling {interval} second platform job")
scheduler.add_job(
platform_job, "interval", seconds=interval, args=[interval]
)
scheduler.start()
loop = asyncio.get_event_loop()
try: