mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add "wait_for_db" management command
This commit is contained in:
parent
8e7e36089b
commit
be41be3981
31
InvenTree/InvenTree/management/commands/wait_for_db.py
Normal file
31
InvenTree/InvenTree/management/commands/wait_for_db.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
"""
|
||||||
|
Custom management command, wait for the database to be ready!
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from django.db import connections
|
||||||
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
django command to pause execution until the database is ready
|
||||||
|
"""
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
self.stdout.write("Waiting for database...")
|
||||||
|
|
||||||
|
db_conn = None
|
||||||
|
|
||||||
|
while not db_conn:
|
||||||
|
try:
|
||||||
|
# get the database with keyword 'default' from settings.py
|
||||||
|
db_conn = connections['default']
|
||||||
|
# prints success messge in green
|
||||||
|
self.stdout.write(self.style.SUCCESS('InvenTree database connected'))
|
||||||
|
except OperationalError:
|
||||||
|
self.stdout.write("Database unavailable, waiting 5 seconds ...")
|
||||||
|
time.sleep(5)
|
@ -9,11 +9,6 @@
|
|||||||
database:
|
database:
|
||||||
# Uncomment (and edit) one of the database configurations below,
|
# Uncomment (and edit) one of the database configurations below,
|
||||||
# or specify database options using environment variables
|
# or specify database options using environment variables
|
||||||
|
|
||||||
# Default installation uses a simple sqlite database
|
|
||||||
# For production, consider changing this!
|
|
||||||
ENGINE: sqlite3
|
|
||||||
NAME: '/home/inventree/database.sqlite3'
|
|
||||||
|
|
||||||
# Refer to the django documentation for full list of options
|
# Refer to the django documentation for full list of options
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ ENV INVENTREE_PORT="${INVENTREE_PORT}"
|
|||||||
|
|
||||||
# InvenTree paths
|
# InvenTree paths
|
||||||
ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src"
|
ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src"
|
||||||
|
ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree"
|
||||||
ENV INVENTREE_STATIC_ROOT="${INVENTREE_HOME}/static"
|
ENV INVENTREE_STATIC_ROOT="${INVENTREE_HOME}/static"
|
||||||
ENV INVENTREE_MEDIA_ROOT="${INVENTREE_HOME}/media"
|
ENV INVENTREE_MEDIA_ROOT="${INVENTREE_HOME}/media"
|
||||||
ENV INVENTREE_LOG_DIR="${INVENTREE_HOME}/log"
|
ENV INVENTREE_LOG_DIR="${INVENTREE_HOME}/log"
|
||||||
|
Loading…
Reference in New Issue
Block a user