-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
698 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: build | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7, 3.8, 3.9, 3.10.0-beta.1] | ||
django: ['Django>=3.1,<3.2', 'Django>=3.2,<3.3'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} and ${{ matrix.django }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Display Python version | ||
run: python -c "import sys; print(sys.version)" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -e . | ||
pip install "${{ matrix.django }}" | ||
- name: Test | ||
run: | | ||
python manage.py test | ||
deploy: | ||
needs: [build] | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* |
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
.idea |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
recursive-include simple_health_check * | ||
include README.md | ||
include LICENSE | ||
global-exclude __pycache__ | ||
global-exclude *.py[co] |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# django-simple-health-check | ||
|
||
[![GitHub Actions](https://github.com/pikhovkin/django-simple-health-check/workflows/build/badge.svg)](https://github.com/pikhovkin/django-simple-health-check/actions) | ||
[![PyPI](https://img.shields.io/pypi/v/django-simple-health-check.svg)](https://pypi.org/project/django-simple-health-check/) | ||
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-simple-health-check.svg) | ||
[![framework - Django](https://img.shields.io/badge/framework-Django-0C3C26.svg)](https://www.djangoproject.com/) | ||
![PyPI - Django Version](https://img.shields.io/pypi/djversions/django-simple-health-check.svg) | ||
[![PyPI - License](https://img.shields.io/pypi/l/django-simple-health-check)](./LICENSE) | ||
|
||
Simple Django health check | ||
|
||
Inspired by: | ||
- [django-alive](https://github.com/lincolnloop/django-alive) | ||
- [django-healthchecks](https://github.com/mvantellingen/django-healthchecks) | ||
- [django-health-check](https://github.com/KristianOellegaard/django-health-check) | ||
- [django-healthz](https://github.com/rehive/django-healthz) | ||
- [django-watchman](https://github.com/mwarkentin/django-watchman) | ||
|
||
### Installation | ||
|
||
```bash | ||
$ pip install django-simple-health-check | ||
``` | ||
|
||
### Quick start | ||
|
||
1. Install the package | ||
|
||
2. Add `simple_health_check` to your INSTALLED_APPS settings like this: | ||
|
||
```python | ||
INSTALLED_APPS = [ | ||
..., | ||
'simple_health_check', | ||
] | ||
``` | ||
|
||
3. Add `simple_health_check.urls` to main `urls.py`: | ||
|
||
```python | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
..., | ||
path('', include('simple_health_check.urls')), | ||
] | ||
``` | ||
|
||
4. Configure the readiness checks: | ||
|
||
```python | ||
SIMPLE_HEALTH_CHECKS = { | ||
'simple_health_check.checks.migrations.Migrations': [ | ||
dict(alias='db1'), | ||
dict(alias='db2'), | ||
], | ||
'simple_health_check.checks.db.Databases': None, | ||
} | ||
``` | ||
|
||
by default | ||
|
||
```python | ||
SIMPLE_HEALTH_CHECKS = { | ||
'simple_health_check.checks.migrations.Migrations': None, # check all aliases | ||
'simple_health_check.checks.db.Databases': None, # check all aliases | ||
} | ||
``` | ||
|
||
## License | ||
|
||
MIT |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.conf.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup | ||
|
||
|
||
setup( | ||
name='django-simple-health-check', | ||
version='0.1.0', | ||
description='Simple Django health check', | ||
long_description=open('README.md').read(), | ||
long_description_content_type='text/markdown', | ||
author='Sergei Pikhovkin', | ||
author_email='[email protected]', | ||
url='https://github.com/pikhovkin/django-simple-health-check', | ||
packages=[ | ||
'simple_health_check', | ||
], | ||
include_package_data=True, | ||
install_requires=[ | ||
'Django>=3.1,<4.0', | ||
], | ||
python_requires='>=3.7.*, <4.0.*', | ||
license='MIT', | ||
zip_safe=False, | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Environment :: Web Environment', | ||
'Framework :: Django :: 3.1', | ||
'Framework :: Django :: 3.2', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python :: 3 :: Only', | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 'simple_health_check.apps.SimpleHealthCheckConfig' |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.apps import AppConfig | ||
from django.conf import settings | ||
from django.utils.module_loading import import_string | ||
|
||
|
||
class SimpleHealthCheckConfig(AppConfig): | ||
name = 'simple_health_check' | ||
|
||
checks = {} | ||
|
||
@classmethod | ||
def register_checks(cls): | ||
cls.checks = {} | ||
SIMPLE_HEALTH_CHECKS = getattr(settings, 'SIMPLE_HEALTH_CHECKS', None) | ||
if SIMPLE_HEALTH_CHECKS is None: | ||
SIMPLE_HEALTH_CHECKS = { | ||
'simple_health_check.checks.migrations.Migrations': None, | ||
'simple_health_check.checks.db.Databases': None, | ||
} | ||
for cls_check, options in SIMPLE_HEALTH_CHECKS.items(): | ||
options = options or {} | ||
if isinstance(options, dict): | ||
options = [options] | ||
elif isinstance(options, (list, set, tuple)): | ||
... | ||
else: | ||
raise | ||
try: | ||
Check = import_string(cls_check) | ||
except Exception: | ||
raise | ||
for opt in options: | ||
identifier = hash(f'{cls_check}.{hash(frozenset((opt or {}).items()))}') | ||
if identifier in cls.checks: | ||
raise | ||
check = Check(**opt) if opt else Check() | ||
cls.checks[identifier] = check | ||
|
||
@classmethod | ||
def check_all(cls): | ||
for check in cls.checks.values(): | ||
check.check() | ||
|
||
def ready(self): | ||
self.register_checks() |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class BaseHealthCheck(object): | ||
def __init__(self, **options): | ||
... | ||
|
||
def check(self): | ||
raise NotImplementedError |
Oops, something went wrong.