mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 15:29:36 +02:00
Merge branch 'development' of github.com:seanmorley15/AdventureLog into development
This commit is contained in:
commit
2ef4917adf
4 changed files with 37 additions and 7 deletions
|
@ -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()
|
|
@ -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)
|
|
@ -46,7 +46,7 @@ def start_scheduler():
|
|||
scheduler.add_job(
|
||||
run_worldtravel_seed,
|
||||
trigger="interval",
|
||||
hours=24,
|
||||
minutes=3,
|
||||
id="worldtravel_seed",
|
||||
max_instances=1,
|
||||
replace_existing=True,
|
||||
|
@ -54,4 +54,3 @@ def start_scheduler():
|
|||
|
||||
logger.info("Starting scheduler...")
|
||||
scheduler.start()
|
||||
return scheduler
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue