From 3cb7545775cf75a81d998c98ba25799c4e9b633c Mon Sep 17 00:00:00 2001 From: "Code Hugger (Matthew Jones)" Date: Thu, 18 Oct 2018 11:23:34 -0400 Subject: [PATCH 1/2] Make watchman constants importable Fixes #130 --- README.rst | 7 +++++++ watchman/constants.py | 8 ++++++++ watchman/settings.py | 10 +--------- 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 watchman/constants.py diff --git a/README.rst b/README.rst index 8e533c1..4ebe4fa 100644 --- a/README.rst +++ b/README.rst @@ -129,6 +129,13 @@ the ``WATCHMAN_CHECKS`` setting. In ``settings.py``:: 'another.module.path.to.callable', ) +You can also import the watchman.constants to include the DEFAULT_CHECKS and PAID_CHECKS in your ``settings.py``:: + + from watchman import constants as watchman_constants + + WATCHMAN_CHECKS = watchman_constants.DEFAULT_CHECKS + ('module.path.to.callable', ) + + Checks take no arguments, and must return a ``dict`` whose keys are applied to the JSON response. Use the ``watchman.decorators.check`` decorator to capture exceptions:: from watchman.decorators import check diff --git a/watchman/constants.py b/watchman/constants.py new file mode 100644 index 0000000..f5ecb7a --- /dev/null +++ b/watchman/constants.py @@ -0,0 +1,8 @@ +DEFAULT_CHECKS = ( + 'watchman.checks.caches', + 'watchman.checks.databases', + 'watchman.checks.storage', +) +PAID_CHECKS = ( + 'watchman.checks.email', +) diff --git a/watchman/settings.py b/watchman/settings.py index 576e7df..b249942 100644 --- a/watchman/settings.py +++ b/watchman/settings.py @@ -1,4 +1,5 @@ from django.conf import settings +from watchman.constants import DEFAULT_CHECKS, PAID_CHECKS # TODO: these should not be module level (https://github.com/mwarkentin/django-watchman/issues/13) WATCHMAN_ENABLE_PAID_CHECKS = getattr(settings, 'WATCHMAN_ENABLE_PAID_CHECKS', False) @@ -17,15 +18,6 @@ WATCHMAN_DISABLE_APM = getattr(settings, 'WATCHMAN_DISABLE_APM', False) -DEFAULT_CHECKS = ( - 'watchman.checks.caches', - 'watchman.checks.databases', - 'watchman.checks.storage', -) -PAID_CHECKS = ( - 'watchman.checks.email', -) - if WATCHMAN_ENABLE_PAID_CHECKS: DEFAULT_CHECKS = DEFAULT_CHECKS + PAID_CHECKS From 17af071faa70d3dc4a884f62fb50f34e8621ac6d Mon Sep 17 00:00:00 2001 From: Michael Warkentin Date: Fri, 19 Oct 2018 09:16:50 -0400 Subject: [PATCH 2/2] Update watchman/constants.py Co-Authored-By: jonespm --- watchman/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/watchman/constants.py b/watchman/constants.py index f5ecb7a..8cd5f95 100644 --- a/watchman/constants.py +++ b/watchman/constants.py @@ -3,6 +3,7 @@ 'watchman.checks.databases', 'watchman.checks.storage', ) + PAID_CHECKS = ( 'watchman.checks.email', )