diff --git a/InvenTree/InvenTree/context.py b/InvenTree/InvenTree/context.py index 9fee5deaab..1d07511fa9 100644 --- a/InvenTree/InvenTree/context.py +++ b/InvenTree/InvenTree/context.py @@ -30,10 +30,20 @@ def health_status(request): request._inventree_health_status = True - return { - "system_healthy": InvenTree.status.check_system_health(), + status = { + 'django_q_running': InvenTree.status.is_q_cluster_running(), } + all_healthy = True + + for k in status.keys(): + if status[k] is not True: + all_healthy = False + + status['system_healthy'] = all_healthy + + return status + def status_codes(request): """ diff --git a/InvenTree/InvenTree/status.py b/InvenTree/InvenTree/status.py index ec2422a254..e02e476a51 100644 --- a/InvenTree/InvenTree/status.py +++ b/InvenTree/InvenTree/status.py @@ -1,15 +1,32 @@ """ Provides system status functionality checks. """ +# -*- coding: utf-8 -*- -from django.utils.translation import ugettext as _ +from __future__ import unicode_literals import logging +from django.utils.translation import ugettext as _ + +from django_q.monitor import Stat logger = logging.getLogger(__name__) +def is_q_cluster_running(**kwargs): + """ + Return True if at least one cluster worker is running + """ + + clusters = Stat.get_all() + + for cluster in clusters: + print("Cluster:", cluster) + + return len(clusters) > 0 + + def check_system_health(**kwargs): """ Check that the InvenTree system is running OK. @@ -19,7 +36,7 @@ def check_system_health(**kwargs): result = True - if not check_celery_worker(**kwargs): + if not is_q_cluster_running(**kwargs): result = False logger.warning(_("Celery worker check failed")) @@ -27,13 +44,3 @@ def check_system_health(**kwargs): logger.warning(_("InvenTree system health checks failed")) return result - - -def check_celery_worker(**kwargs): - """ - Check that a celery worker is running. - """ - - # TODO - Checks that the configured celery worker thing is running - - return True diff --git a/InvenTree/templates/stats.html b/InvenTree/templates/stats.html index 7b8a9bb93a..30d3f3d881 100644 --- a/InvenTree/templates/stats.html +++ b/InvenTree/templates/stats.html @@ -13,8 +13,9 @@