Commit 2739e351 authored by Jens Langhammer's avatar Jens Langhammer

[core] move celery workers to API

parent d8b37c38
"""Supervisr Core APIv1"""
import celery
from django.core.cache import cache
from supervisr.core.api.base import API
from supervisr.core.signals import get_module_health
from supervisr.core.utils import check_db_connection
from supervisr.core.exceptions import UnauthorizedException
class SystemAPI(API):
"""System API"""
'GET': ['health']
'GET': ['health', 'workers']
......@@ -37,3 +39,16 @@ class SystemAPI(API):
# Get the handler's root module
data[handler.__module__] = mod_info
return data
def workers(self, request, data):
"""Get celery worker list"""
if not request.user.is_superuser:
raise UnauthorizedException()
celery_dict = celery.current_app.control.inspect().ping()
workers = []
for worker_name, worker_status in celery_dict.items():
'name': worker_name,
'status': worker_status.get('ok')
return workers
......@@ -3,7 +3,6 @@
import platform
import sys
import celery
from django import get_version as django_version
from django.conf import settings as django_settings
from django.contrib import messages
......@@ -30,7 +29,6 @@ class IndexView(TemplateView, AdminRequiredMixin):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['user_count'] = User.objects.all().count() - 1
context['celery_workers'] = celery.current_app.control.inspect().ping()
return context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment