Renew with 2FA and Podman
This commit is contained in:
41
core/management/commands/scheduling.py
Normal file
41
core/management/commands/scheduling.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import asyncio
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from core.util import logs
|
||||
|
||||
log = logs.get_logger("scheduling")
|
||||
|
||||
INTERVALS = [5, 60, 900, 1800, 3600, 14400, 86400]
|
||||
|
||||
|
||||
async def job(interval_seconds):
|
||||
"""
|
||||
Run all schedules matching the given interval.
|
||||
:param interval_seconds: The interval to run.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
"""
|
||||
Start the scheduling process.
|
||||
"""
|
||||
scheduler = AsyncIOScheduler()
|
||||
for interval in INTERVALS:
|
||||
log.debug(f"Scheduling {interval} second job")
|
||||
scheduler.add_job(job, "interval", seconds=interval, args=[interval])
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
scheduler._eventloop = loop
|
||||
scheduler.start()
|
||||
try:
|
||||
loop.run_forever()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
log.info("Process terminating")
|
||||
finally:
|
||||
loop.close()
|
||||
Reference in New Issue
Block a user