File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010from dojo .forms import SystemSettingsForm
1111from dojo .models import System_Settings
12- from dojo .utils import add_breadcrumb , get_celery_worker_status
12+ from dojo .utils import add_breadcrumb , get_celery_queue_length , get_celery_worker_status
1313
1414logger = logging .getLogger (__name__ )
1515
@@ -110,6 +110,15 @@ def get_celery_status(
110110 else :
111111 context ["celery_msg" ] = "Celery does not appear to be up and running. Please ensure celery is running."
112112 context ["celery_status" ] = "Not Running"
113+
114+ q_len = get_celery_queue_length ()
115+ if q_len is None :
116+ context ["celery_q_len" ] = " It is not possible to identify number of waiting tasks."
117+ elif q_len :
118+ context ["celery_q_len" ] = f"{ q_len } tasks are waiting to be proccessed."
119+ else :
120+ context ["celery_q_len" ] = "No task is waiting to be proccessed."
121+
113122 else :
114123 context ["celery_bool" ] = False
115124 context ["celery_msg" ] = "Celery needs to have the setting CELERY_RESULT_BACKEND = 'db+sqlite:///dojo.celeryresults.sqlite' set in settings.py."
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ <h4> Celery <span class="label label-danger">{{celery_status}}</span> </h4>
2626 < div class ="panel-body text-left ">
2727 {{celery_msg}}
2828 </ div >
29+ < div class ="panel-body text-left ">
30+ {{celery_q_len}}
31+ </ div >
2932 </ div >
3033 </ div >
3134 </ div >
Original file line number Diff line number Diff line change 2020import crum
2121import cvss
2222import vobject
23+ from amqp .exceptions import ChannelError
2324from auditlog .models import LogEntry
2425from cryptography .hazmat .backends import default_backend
2526from cryptography .hazmat .primitives .ciphers import Cipher , algorithms , modes
4243from django .utils import timezone
4344from django .utils .http import url_has_allowed_host_and_scheme
4445from django .utils .translation import gettext as _
46+ from kombu import Connection
4547
4648from dojo .authorization .roles_permissions import Permissions
4749from dojo .celery import app
@@ -1322,6 +1324,18 @@ def get_celery_worker_status():
13221324 return False
13231325
13241326
1327+ def get_celery_queue_length ():
1328+ try :
1329+ with Connection (settings .CELERY_BROKER_URL ) as conn , conn .SimpleQueue ("celery" ) as queue :
1330+ return queue .qsize ()
1331+ except ChannelError as e :
1332+ if "NOT_FOUND" in str (e ):
1333+ return 0
1334+ return None
1335+ except :
1336+ return None
1337+
1338+
13251339# Used to display the counts and enabled tabs in the product view
13261340# Uses @cached_property for lazy loading to avoid expensive queries on every page load
13271341# See: https://github.com/DefectDojo/django-DefectDojo/issues/10313
You can’t perform that action at this time.
0 commit comments