Skip to content

Commit 5b37703

Browse files
authored
feat(async): Show number of tasks waiting in queue (#14180)
Signed-off-by: kiblik <5609770+kiblik@users.noreply.github.com>
1 parent ebc9a44 commit 5b37703

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

dojo/system_settings/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from dojo.forms import SystemSettingsForm
1111
from 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

1414
logger = 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."

dojo/templates/dojo/system_settings.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

dojo/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import crum
2121
import cvss
2222
import vobject
23+
from amqp.exceptions import ChannelError
2324
from auditlog.models import LogEntry
2425
from cryptography.hazmat.backends import default_backend
2526
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@@ -42,6 +43,7 @@
4243
from django.utils import timezone
4344
from django.utils.http import url_has_allowed_host_and_scheme
4445
from django.utils.translation import gettext as _
46+
from kombu import Connection
4547

4648
from dojo.authorization.roles_permissions import Permissions
4749
from 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

0 commit comments

Comments
 (0)