Add more interval choices
This commit is contained in:
parent
5f0c555aa3
commit
8dc1e83d0a
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.1.7 on 2023-03-11 17:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0016_alter_platform_cheat_interval_seconds'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='platform',
|
||||
name='cheat_interval_seconds',
|
||||
field=models.IntegerField(choices=[(0, 'Never'), (5, 'Every 5 seconds'), (15, 'Every 15 seconds'), (30, 'Every 30 seconds'), (60, 'Every minute'), (300, 'Every 5 minutes'), (600, 'Every 10 minutes'), (3600, 'Every hour'), (14400, 'Every 4 hours'), (86400, 'Every day')], default=0),
|
||||
),
|
||||
]
|
|
@ -13,6 +13,10 @@ SERVICE_CHOICES = (("nordigen", "Nordigen"),)
|
|||
PLATFORM_SERVICE_CHOICES = (("agora", "Agora"),)
|
||||
|
||||
INTERVAL_CHOICES = (
|
||||
(0, "Never"),
|
||||
(5, "Every 5 seconds"),
|
||||
(15, "Every 15 seconds"),
|
||||
(30, "Every 30 seconds"),
|
||||
(60, "Every minute"),
|
||||
(60 * 5, "Every 5 minutes"),
|
||||
(60 * 10, "Every 10 minutes"),
|
||||
|
@ -118,7 +122,7 @@ class Platform(models.Model):
|
|||
send = models.BooleanField(default=True)
|
||||
cheat = models.BooleanField(default=False)
|
||||
dummy = models.BooleanField(default=False)
|
||||
cheat_interval_seconds = models.IntegerField(default=3600, choices=INTERVAL_CHOICES)
|
||||
cheat_interval_seconds = models.IntegerField(default=0, choices=INTERVAL_CHOICES)
|
||||
|
||||
margin = models.FloatField(default=1.20)
|
||||
max_margin = models.FloatField(default=1.30)
|
||||
|
|
Loading…
Reference in New Issue