mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
Fix scheduler
This commit is contained in:
parent
2ef4917adf
commit
704d26f867
2 changed files with 3 additions and 32 deletions
|
@ -1,30 +0,0 @@
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
from django.db import connections
|
|
||||||
from django.db.utils import OperationalError
|
|
||||||
import time
|
|
||||||
from adventures.scheduler import start_scheduler
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = 'Starts the APScheduler'
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
self.stdout.write('Waiting for database...')
|
|
||||||
db_conn = None
|
|
||||||
while not db_conn:
|
|
||||||
try:
|
|
||||||
db_conn = connections['default']
|
|
||||||
except OperationalError:
|
|
||||||
self.stdout.write('Database unavailable, waiting 1 second...')
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS('Database available!'))
|
|
||||||
|
|
||||||
start_scheduler()
|
|
||||||
self.stdout.write(self.style.SUCCESS('Scheduler started successfully'))
|
|
||||||
|
|
||||||
# Keep the command running
|
|
||||||
while True:
|
|
||||||
time.sleep(60)
|
|
|
@ -46,7 +46,7 @@ def start_scheduler():
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
run_worldtravel_seed,
|
run_worldtravel_seed,
|
||||||
trigger="interval",
|
trigger="interval",
|
||||||
minutes=3,
|
hours=24,
|
||||||
id="worldtravel_seed",
|
id="worldtravel_seed",
|
||||||
max_instances=1,
|
max_instances=1,
|
||||||
replace_existing=True,
|
replace_existing=True,
|
||||||
|
@ -54,3 +54,4 @@ def start_scheduler():
|
||||||
|
|
||||||
logger.info("Starting scheduler...")
|
logger.info("Starting scheduler...")
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
return scheduler
|
Loading…
Add table
Add a link
Reference in a new issue