Skip to content

Commit e7bd5f5

Browse files
committed
Initial
1 parent 7e1458f commit e7bd5f5

25 files changed

+698
-0
lines changed

.github/workflows/python-package.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: build
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
release:
12+
types: [created]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [3.7, 3.8, 3.9, 3.10.0-beta.1]
20+
django: ['Django>=3.1,<3.2', 'Django>=3.2,<3.3']
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up Python ${{ matrix.python-version }} and ${{ matrix.django }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Display Python version
29+
run: python -c "import sys; print(sys.version)"
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install -e .
34+
pip install "${{ matrix.django }}"
35+
- name: Test
36+
run: |
37+
python manage.py test
38+
39+
deploy:
40+
needs: [build]
41+
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- uses: actions/checkout@v2
46+
- name: Set up Python
47+
uses: actions/setup-python@v2
48+
with:
49+
python-version: '3.x'
50+
- name: Install dependencies
51+
run: |
52+
python -m pip install --upgrade pip
53+
pip install setuptools wheel twine
54+
- name: Build and publish
55+
env:
56+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
57+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
58+
run: |
59+
python setup.py sdist bdist_wheel
60+
twine upload dist/*

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.pot
56+
57+
# Django stuff:
58+
*.log
59+
local_settings.py
60+
db.sqlite3
61+
db.sqlite3-journal
62+
63+
# Flask stuff:
64+
instance/
65+
.webassets-cache
66+
67+
# Scrapy stuff:
68+
.scrapy
69+
70+
# Sphinx documentation
71+
docs/_build/
72+
73+
# PyBuilder
74+
target/
75+
76+
# Jupyter Notebook
77+
.ipynb_checkpoints
78+
79+
# IPython
80+
profile_default/
81+
ipython_config.py
82+
83+
# pyenv
84+
.python-version
85+
86+
# pipenv
87+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
88+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
89+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
90+
# install all needed dependencies.
91+
#Pipfile.lock
92+
93+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
94+
__pypackages__/
95+
96+
# Celery stuff
97+
celerybeat-schedule
98+
celerybeat.pid
99+
100+
# SageMath parsed files
101+
*.sage.py
102+
103+
# Environments
104+
.env
105+
.venv
106+
env/
107+
venv/
108+
ENV/
109+
env.bak/
110+
venv.bak/
111+
112+
# Spyder project settings
113+
.spyderproject
114+
.spyproject
115+
116+
# Rope project settings
117+
.ropeproject
118+
119+
# mkdocs documentation
120+
/site
121+
122+
# mypy
123+
.mypy_cache/
124+
.dmypy.json
125+
dmypy.json
126+
127+
# Pyre type checker
128+
.pyre/
129+
130+
.idea

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
recursive-include simple_health_check *
2+
include README.md
3+
include LICENSE
4+
global-exclude __pycache__
5+
global-exclude *.py[co]

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# django-simple-health-check
2+
3+
[![GitHub Actions](https://github.com/pikhovkin/django-simple-health-check/workflows/build/badge.svg)](https://github.com/pikhovkin/django-simple-health-check/actions)
4+
[![PyPI](https://img.shields.io/pypi/v/django-simple-health-check.svg)](https://pypi.org/project/django-simple-health-check/)
5+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-simple-health-check.svg)
6+
[![framework - Django](https://img.shields.io/badge/framework-Django-0C3C26.svg)](https://www.djangoproject.com/)
7+
![PyPI - Django Version](https://img.shields.io/pypi/djversions/django-simple-health-check.svg)
8+
[![PyPI - License](https://img.shields.io/pypi/l/django-simple-health-check)](./LICENSE)
9+
10+
Simple Django health check
11+
12+
Inspired by:
13+
- [django-alive](https://github.com/lincolnloop/django-alive)
14+
- [django-healthchecks](https://github.com/mvantellingen/django-healthchecks)
15+
- [django-health-check](https://github.com/KristianOellegaard/django-health-check)
16+
- [django-healthz](https://github.com/rehive/django-healthz)
17+
- [django-watchman](https://github.com/mwarkentin/django-watchman)
18+
19+
### Installation
20+
21+
```bash
22+
$ pip install django-simple-health-check
23+
```
24+
25+
### Quick start
26+
27+
1. Install the package
28+
29+
2. Add `simple_health_check` to your INSTALLED_APPS settings like this:
30+
31+
```python
32+
INSTALLED_APPS = [
33+
...,
34+
'simple_health_check',
35+
]
36+
```
37+
38+
3. Add `simple_health_check.urls` to main `urls.py`:
39+
40+
```python
41+
from django.urls import path, include
42+
43+
urlpatterns = [
44+
...,
45+
path('', include('simple_health_check.urls')),
46+
]
47+
```
48+
49+
4. Configure the readiness checks:
50+
51+
```python
52+
SIMPLE_HEALTH_CHECKS = {
53+
'simple_health_check.checks.migrations.Migrations': [
54+
dict(alias='db1'),
55+
dict(alias='db2'),
56+
],
57+
'simple_health_check.checks.db.Databases': None,
58+
}
59+
```
60+
61+
by default
62+
63+
```python
64+
SIMPLE_HEALTH_CHECKS = {
65+
'simple_health_check.checks.migrations.Migrations': None, # check all aliases
66+
'simple_health_check.checks.db.Databases': None, # check all aliases
67+
}
68+
```
69+
70+
## License
71+
72+
MIT

manage.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
6+
def main():
7+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.conf.settings')
8+
try:
9+
from django.core.management import execute_from_command_line
10+
except ImportError as exc:
11+
raise ImportError(
12+
"Couldn't import Django. Are you sure it's installed and "
13+
"available on your PYTHONPATH environment variable? Did you "
14+
"forget to activate a virtual environment?"
15+
) from exc
16+
execute_from_command_line(sys.argv)
17+
18+
19+
if __name__ == '__main__':
20+
main()

setup.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
try:
3+
from setuptools import setup
4+
except ImportError:
5+
from distutils.core import setup
6+
7+
8+
setup(
9+
name='django-simple-health-check',
10+
version='0.1.0',
11+
description='Simple Django health check',
12+
long_description=open('README.md').read(),
13+
long_description_content_type='text/markdown',
14+
author='Sergei Pikhovkin',
15+
author_email='[email protected]',
16+
url='https://github.com/pikhovkin/django-simple-health-check',
17+
packages=[
18+
'simple_health_check',
19+
],
20+
include_package_data=True,
21+
install_requires=[
22+
'Django>=3.1,<4.0',
23+
],
24+
python_requires='>=3.7.*, <4.0.*',
25+
license='MIT',
26+
zip_safe=False,
27+
classifiers=[
28+
'Development Status :: 3 - Alpha',
29+
'Environment :: Web Environment',
30+
'Framework :: Django :: 3.1',
31+
'Framework :: Django :: 3.2',
32+
'Intended Audience :: Developers',
33+
'License :: OSI Approved :: MIT License',
34+
'Operating System :: OS Independent',
35+
'Programming Language :: Python :: 3 :: Only',
36+
'Programming Language :: Python :: 3.7',
37+
'Programming Language :: Python :: 3.8',
38+
'Programming Language :: Python :: 3.9',
39+
'Programming Language :: Python :: 3.10',
40+
],
41+
)

simple_health_check/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default_app_config = 'simple_health_check.apps.SimpleHealthCheckConfig'

simple_health_check/apps.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from django.apps import AppConfig
2+
from django.conf import settings
3+
from django.utils.module_loading import import_string
4+
5+
6+
class SimpleHealthCheckConfig(AppConfig):
7+
name = 'simple_health_check'
8+
9+
checks = {}
10+
11+
@classmethod
12+
def register_checks(cls):
13+
cls.checks = {}
14+
SIMPLE_HEALTH_CHECKS = getattr(settings, 'SIMPLE_HEALTH_CHECKS', None)
15+
if SIMPLE_HEALTH_CHECKS is None:
16+
SIMPLE_HEALTH_CHECKS = {
17+
'simple_health_check.checks.migrations.Migrations': None,
18+
'simple_health_check.checks.db.Databases': None,
19+
}
20+
for cls_check, options in SIMPLE_HEALTH_CHECKS.items():
21+
options = options or {}
22+
if isinstance(options, dict):
23+
options = [options]
24+
elif isinstance(options, (list, set, tuple)):
25+
...
26+
else:
27+
raise
28+
try:
29+
Check = import_string(cls_check)
30+
except Exception:
31+
raise
32+
for opt in options:
33+
identifier = hash(f'{cls_check}.{hash(frozenset((opt or {}).items()))}')
34+
if identifier in cls.checks:
35+
raise
36+
check = Check(**opt) if opt else Check()
37+
cls.checks[identifier] = check
38+
39+
@classmethod
40+
def check_all(cls):
41+
for check in cls.checks.values():
42+
check.check()
43+
44+
def ready(self):
45+
self.register_checks()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class BaseHealthCheck(object):
2+
def __init__(self, **options):
3+
...
4+
5+
def check(self):
6+
raise NotImplementedError

0 commit comments

Comments
 (0)