django-wait-for-db 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Fournet Enzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-wait-for-db
3
+ Version: 1.0.1
4
+ Summary: Simple Django app that provides a simple command to wait for the database to be ready before starting the server.
5
+ Home-page: https://github.com/enzofrnt/django_wait_for_db
6
+ Author: enzo_frnt
7
+ Author-email: contact@enzo-frnt.fr
8
+ License: MIT
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: Django
25
+
26
+ # django_wait_for_db
27
+ Django app that provides a simple command to wait for the database to be ready before starting the server.
28
+
29
+ ## Usage
30
+
31
+ Add `django_wait_for_db` to your `INSTALLED_APPS`:
32
+
33
+ ```python
34
+ INSTALLED_APPS = [
35
+ ...
36
+ 'wait_for_db',
37
+ ...
38
+ ]
39
+ ```
40
+
41
+ Then run the following command:
42
+
43
+ ```bash
44
+ python manage.py wait_for_db
45
+ ```
46
+
47
+ This will wait for the database to be ready before starting the server.
48
+ This is useful when you are using Docker and you want to start the Django server before the database is ready or when you are in an environment where the database is not always available when the Django server starts.
49
+
50
+ Exemple of a Dockerfile:
51
+
52
+ ```Dockerfile
53
+ FROM python:3.8
54
+
55
+ (.......)
56
+
57
+ CMD python manage.py wait_for_db \
58
+ && python manage.py runserver
59
+ ```
@@ -0,0 +1,34 @@
1
+ # django_wait_for_db
2
+ Django app that provides a simple command to wait for the database to be ready before starting the server.
3
+
4
+ ## Usage
5
+
6
+ Add `django_wait_for_db` to your `INSTALLED_APPS`:
7
+
8
+ ```python
9
+ INSTALLED_APPS = [
10
+ ...
11
+ 'wait_for_db',
12
+ ...
13
+ ]
14
+ ```
15
+
16
+ Then run the following command:
17
+
18
+ ```bash
19
+ python manage.py wait_for_db
20
+ ```
21
+
22
+ This will wait for the database to be ready before starting the server.
23
+ This is useful when you are using Docker and you want to start the Django server before the database is ready or when you are in an environment where the database is not always available when the Django server starts.
24
+
25
+ Exemple of a Dockerfile:
26
+
27
+ ```Dockerfile
28
+ FROM python:3.8
29
+
30
+ (.......)
31
+
32
+ CMD python manage.py wait_for_db \
33
+ && python manage.py runserver
34
+ ```
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-wait-for-db
3
+ Version: 1.0.1
4
+ Summary: Simple Django app that provides a simple command to wait for the database to be ready before starting the server.
5
+ Home-page: https://github.com/enzofrnt/django_wait_for_db
6
+ Author: enzo_frnt
7
+ Author-email: contact@enzo-frnt.fr
8
+ License: MIT
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: Django
25
+
26
+ # django_wait_for_db
27
+ Django app that provides a simple command to wait for the database to be ready before starting the server.
28
+
29
+ ## Usage
30
+
31
+ Add `django_wait_for_db` to your `INSTALLED_APPS`:
32
+
33
+ ```python
34
+ INSTALLED_APPS = [
35
+ ...
36
+ 'wait_for_db',
37
+ ...
38
+ ]
39
+ ```
40
+
41
+ Then run the following command:
42
+
43
+ ```bash
44
+ python manage.py wait_for_db
45
+ ```
46
+
47
+ This will wait for the database to be ready before starting the server.
48
+ This is useful when you are using Docker and you want to start the Django server before the database is ready or when you are in an environment where the database is not always available when the Django server starts.
49
+
50
+ Exemple of a Dockerfile:
51
+
52
+ ```Dockerfile
53
+ FROM python:3.8
54
+
55
+ (.......)
56
+
57
+ CMD python manage.py wait_for_db \
58
+ && python manage.py runserver
59
+ ```
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ django_wait_for_db.egg-info/PKG-INFO
5
+ django_wait_for_db.egg-info/SOURCES.txt
6
+ django_wait_for_db.egg-info/dependency_links.txt
7
+ django_wait_for_db.egg-info/not-zip-safe
8
+ django_wait_for_db.egg-info/requires.txt
9
+ django_wait_for_db.egg-info/top_level.txt
10
+ wait_for_db/__init__.py
11
+ wait_for_db/apps.py
12
+ wait_for_db/management/commands/wait_for_db.py
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,41 @@
1
+ import os
2
+ from setuptools import setup
3
+
4
+ with open(os.path.join(os.path.dirname(__file__), "README.md")) as f:
5
+ readme = f.read()
6
+
7
+ setup(
8
+ name="django-wait-for-db",
9
+ version="1.0.1",
10
+ description="Simple Django app that provides a simple command to wait for the database to be ready before starting the server.",
11
+ long_description=readme,
12
+ long_description_content_type="text/markdown",
13
+ author="enzo_frnt",
14
+ author_email="contact@enzo-frnt.fr",
15
+ url="https://github.com/enzofrnt/django_wait_for_db",
16
+ license="MIT",
17
+ zip_safe=False,
18
+ packages=[
19
+ "wait_for_db",
20
+ "wait_for_db.management",
21
+ "wait_for_db.management.commands",
22
+ ],
23
+ install_requires=[
24
+ "Django",
25
+ ],
26
+ classifiers=[
27
+ "Development Status :: 5 - Production/Stable",
28
+ "Environment :: Web Environment",
29
+ "Framework :: Django",
30
+ "Intended Audience :: Developers",
31
+ "License :: OSI Approved :: MIT License",
32
+ "Operating System :: OS Independent",
33
+ "Programming Language :: Python",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.7",
36
+ "Programming Language :: Python :: 3.8",
37
+ "Programming Language :: Python :: 3.9",
38
+ "Programming Language :: Python :: 3.10",
39
+ "Topic :: Software Development :: Libraries",
40
+ ],
41
+ )
File without changes
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class WaitForDbConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'wait_for_db'
@@ -0,0 +1,24 @@
1
+ import time
2
+
3
+ from django.db import connections
4
+ from django.db.utils import OperationalError
5
+ from django.core.management.base import BaseCommand
6
+ from django.db import DEFAULT_DB_ALIAS
7
+ from django.conf import settings
8
+
9
+
10
+ class Command(BaseCommand):
11
+ """Django command to pause execution until database is available"""
12
+
13
+ def handle(self, *args, **options):
14
+ """Handle the command"""
15
+ self.stdout.write('Waiting for database...')
16
+ while True:
17
+ try:
18
+ db_conn = connections[DEFAULT_DB_ALIAS]
19
+ db_conn.ensure_connection()
20
+ self.stdout.write(self.style.SUCCESS('Database available!'))
21
+ break
22
+ except OperationalError:
23
+ self.stdout.write(f'Database unavailable on {settings.DATABASES["default"]["HOST"]}:{settings.DATABASES["default"]["PORT"]}, waiting 1 second...')
24
+ time.sleep(1)