-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configured Docker compose and wait for db
- Loading branch information
1 parent
1766c32
commit 0d20d82
Showing
6 changed files
with
28 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin # noqa | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
""" | ||
Django command for the database to be available. | ||
Django command to wait for the database to be available. | ||
""" | ||
import time | ||
|
||
from typing import Any | ||
from django.core.management import BaseCommand | ||
from psycopg2 import OperationalError as Psycopg2OpError | ||
|
||
from django.db.utils import OperationalError | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Django command to wait for database""" | ||
"""Django command to wait for database.""" | ||
|
||
def handle(self, *args: Any, **options: Any): | ||
pass | ||
def handle(self, *args, **options): | ||
"""Entrypoint for command.""" | ||
self.stdout.write('Waiting for database...') | ||
db_up = False | ||
while db_up is False: | ||
try: | ||
self.check(databases=['default']) | ||
db_up = True | ||
except (Psycopg2OpError, OperationalError): | ||
self.stdout.write('Database unavailable, waiting 1 second...') | ||
time.sleep(1) | ||
self.stdout.write(self.style.SUCCESS('Database available!')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django.db import models | ||
from django.db import models # noqa | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters