|
| 1 | +{% extends "base.html" %} |
| 2 | +{% load static %} |
| 3 | + |
| 4 | +{% block content %} |
| 5 | + {{ block.super }} |
| 6 | + <div class="row"> |
| 7 | + <h3>System Status</h3> |
| 8 | + <br> |
| 9 | + <div id="celery-status-panel" class="col-md-5"> |
| 10 | + <div class="panel panel-default"> |
| 11 | + <div class="panel-heading"> |
| 12 | + <h4>Celery <span id="celery-status-badge" class="label label-default">Loading...</span></h4> |
| 13 | + </div> |
| 14 | + <div class="panel-body text-left" id="celery-status-msg">—</div> |
| 15 | + <div class="panel-body text-left"> |
| 16 | + <span id="celery-queue-msg">—</span> |
| 17 | + <div style="margin-top: 8px;"> |
| 18 | + <button id="purge-queue-btn" class="btn btn-danger btn-xs" disabled title="Loading..."> |
| 19 | + Purge queue |
| 20 | + </button> |
| 21 | + <button id="refresh-status-btn" class="btn btn-default btn-xs" style="margin-left: 6px;"> |
| 22 | + <span class="glyphicon glyphicon-refresh"></span> Refresh |
| 23 | + </button> |
| 24 | + </div> |
| 25 | + <p class="text-muted" style="margin-top: 8px; font-size: 0.9em"> |
| 26 | + <strong>Note:</strong> Purging the queue removes pending tasks that have not yet been executed, |
| 27 | + including deduplication tasks. If deduplication tasks were in the queue, you may need to |
| 28 | + re-run deduplication manually using the <code>dedupe</code> management command: |
| 29 | + <code>python manage.py dedupe</code> |
| 30 | + </p> |
| 31 | + </div> |
| 32 | + <div class="panel-body text-left"> |
| 33 | + <table class="table table-condensed" style="margin-bottom: 0"> |
| 34 | + <thead><tr><th>Setting</th><th>Value</th></tr></thead> |
| 35 | + <tbody id="celery-config-tbody"></tbody> |
| 36 | + <tfoot> |
| 37 | + <tr> |
| 38 | + <td colspan="2" class="text-muted" style="font-size: 0.9em; border-top: 1px solid #ddd; padding-top: 6px"> |
| 39 | + Read-only. Configured via environment variables: |
| 40 | + <code>DD_CELERY_TASK_TIME_LIMIT</code>, |
| 41 | + <code>DD_CELERY_TASK_SOFT_TIME_LIMIT</code>, |
| 42 | + <code>DD_CELERY_TASK_DEFAULT_EXPIRES</code> |
| 43 | + </td> |
| 44 | + </tr> |
| 45 | + </tfoot> |
| 46 | + </table> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | +{% endblock content %} |
| 52 | + |
| 53 | +{% block postscript %} |
| 54 | + {{ block.super }} |
| 55 | + <script> |
| 56 | + (function() { |
| 57 | + var purgeUrl = "{% url 'celery_queue_purge_api' %}"; |
| 58 | + var statusUrl = "{% url 'celery_status_api' %}"; |
| 59 | + |
| 60 | + function renderCeleryStatus(data) { |
| 61 | + var badge = $('#celery-status-badge'); |
| 62 | + if (data.worker_status) { |
| 63 | + badge.text('Running').removeClass('label-default label-danger').addClass('label-success'); |
| 64 | + $('#celery-status-msg').text('Celery is processing tasks.'); |
| 65 | + } else { |
| 66 | + badge.text('Not Running').removeClass('label-default label-success').addClass('label-danger'); |
| 67 | + $('#celery-status-msg').text('Celery does not appear to be running.'); |
| 68 | + } |
| 69 | + |
| 70 | + var qLen = data.queue_length; |
| 71 | + if (qLen === null) { |
| 72 | + $('#celery-queue-msg').text('It is not possible to identify the number of waiting tasks.'); |
| 73 | + $('#purge-queue-btn').prop('disabled', true).attr('title', 'Broker unreachable'); |
| 74 | + } else { |
| 75 | + $('#celery-queue-msg').text(qLen + ' task(s) waiting to be processed.'); |
| 76 | + $('#purge-queue-btn').prop('disabled', false).removeAttr('title'); |
| 77 | + } |
| 78 | + |
| 79 | + function humanDuration(seconds) { |
| 80 | + if (seconds === null) return '<em>Not set</em>'; |
| 81 | + var d = Math.floor(seconds / 86400); |
| 82 | + var h = Math.floor((seconds % 86400) / 3600); |
| 83 | + var m = Math.floor((seconds % 3600) / 60); |
| 84 | + var s = seconds % 60; |
| 85 | + var parts = []; |
| 86 | + if (d) parts.push(d + 'd'); |
| 87 | + if (h) parts.push(h + 'h'); |
| 88 | + if (m) parts.push(m + 'm'); |
| 89 | + if (s || parts.length === 0) parts.push(s + 's'); |
| 90 | + return parts.join(' ') + ' <span class="text-muted">(' + seconds + 's)</span>'; |
| 91 | + } |
| 92 | + |
| 93 | + var cfgRows = [ |
| 94 | + ['Task time limit (hard kill)', data.task_time_limit], |
| 95 | + ['Task soft time limit', data.task_soft_time_limit], |
| 96 | + ['Default task expiry (queue)', data.task_default_expires], |
| 97 | + ]; |
| 98 | + var tbody = $('#celery-config-tbody').empty(); |
| 99 | + cfgRows.forEach(function(row) { |
| 100 | + tbody.append('<tr><td>' + row[0] + '</td><td>' + humanDuration(row[1]) + '</td></tr>'); |
| 101 | + }); |
| 102 | + } |
| 103 | + |
| 104 | + function loadCeleryStatus() { |
| 105 | + $.get(statusUrl).done(renderCeleryStatus).fail(function() { |
| 106 | + $('#celery-status-badge').text('Error').removeClass('label-default label-success').addClass('label-danger'); |
| 107 | + $('#celery-status-msg').text('Failed to load Celery status.'); |
| 108 | + }); |
| 109 | + } |
| 110 | + |
| 111 | + $(function() { |
| 112 | + loadCeleryStatus(); |
| 113 | + |
| 114 | + $('#refresh-status-btn').on('click', loadCeleryStatus); |
| 115 | + |
| 116 | + $('#purge-queue-btn').on('click', function() { |
| 117 | + if (!confirm('Purge all pending tasks from the queue? This cannot be undone.')) return; |
| 118 | + $.ajax({ |
| 119 | + url: purgeUrl, |
| 120 | + method: 'POST', |
| 121 | + headers: {'X-CSRFToken': '{{ csrf_token }}'}, |
| 122 | + }).done(function(data) { |
| 123 | + location.reload(); |
| 124 | + }).fail(function() { |
| 125 | + alert('Purge failed. Check server logs.'); |
| 126 | + loadCeleryStatus(); |
| 127 | + }); |
| 128 | + }); |
| 129 | + }); |
| 130 | + })(); |
| 131 | + </script> |
| 132 | +{% endblock %} |
0 commit comments