1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 07:19:36 +02:00

Merge branch 'development' of github.com:seanmorley15/AdventureLog into development

This commit is contained in:
Sean Morley 2024-08-21 10:05:13 -04:00
commit 2ef4917adf
4 changed files with 37 additions and 7 deletions

View file

@ -7,5 +7,6 @@ class AdventuresConfig(AppConfig):
def ready(self):
if settings.SCHEDULER_AUTOSTART:
from .scheduler import start_scheduler
start_scheduler()
from django.core.management import call_command
import threading
threading.Thread(target=call_command, args=('start_scheduler',)).start()

View file

@ -0,0 +1,30 @@
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)

View file

@ -46,12 +46,11 @@ def start_scheduler():
scheduler.add_job(
run_worldtravel_seed,
trigger="interval",
hours=24,
minutes=3,
id="worldtravel_seed",
max_instances=1,
replace_existing=True,
)
logger.info("Starting scheduler...")
scheduler.start()
return scheduler
scheduler.start()

View file

@ -23,8 +23,8 @@ services:
- postgres_data:/var/lib/postgresql/data/
server:
#build: ./backend/
image: ghcr.io/seanmorley15/adventurelog-backend:latest
build: ./backend/
#image: ghcr.io/seanmorley15/adventurelog-backend:latest
environment:
- PGHOST=db
- PGDATABASE=database