Skip to content

Commit

Permalink
Make failed jobs sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
selwin committed Oct 19, 2024
1 parent 40f109f commit 9722a96
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 4 deletions.
170 changes: 170 additions & 0 deletions django_rq/templates/django_rq/failed_jobs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{% extends "admin/base_site.html" %}

{% load static jquery_path django_rq %}

{% block title %}{{ job_status }} Jobs in {{ queue.name }} {{ block.super }}{% endblock %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
{% endblock %}

{% block extrahead %}
{{ block.super }}
<script type="text/javascript" src="{% get_jquery_path as jquery_path %}{% static jquery_path %}"></script>
<script type="text/javascript" src="{% static "admin/js/jquery.init.js" %}"></script>
<script type="text/javascript" src="{% static "admin/js/actions.js" %}"></script>
<script type="text/javascript">
(function($) {
$(document).ready(function($) {
$("tr input.action-select").actions();
});
})(django.jQuery);
</script>
{% endblock %}


{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">Home</a> &rsaquo;
<a href="{% url 'rq_home' %}">Django RQ</a> &rsaquo;
<a href="{% url 'rq_jobs' queue_index %}">{{ queue.name }}</a>
</div>
{% endblock %}

{% block content_title %}<h1>{{ job_status }} jobs in {{ queue.name }}</h1>{% endblock %}

{% block content %}

<div id="content-main">
<ul class="object-tools">
<li><a href="{% url 'rq_requeue_all' queue_index %}" class="requeuelink">Requeue All</a></li>
<li><a href="{% url 'rq_delete_failed_jobs' queue_index %}" class="requeuelink">Delete All</a></li>
</ul>
<div class="module" id="changelist">
<div class="changelist-form-container">
<form id="changelist-form" action="{% url 'rq_confirm_action' queue_index %}" method="post">
{% csrf_token %}
<div class="actions">
<label>Actions:
<select name="action" required>
<option value="" selected>---------</option>
<option value="delete">Delete</option>
<option value="requeue">Requeue</option>
</select>
</label>
<button type="submit" class="button" title="Execute selected action" name="index" value="0">Go</button>
</div>
<div class="results">
<table id="result_list">
<thead>
<tr>
<th scope="col" class="action-checkbox-column">
<div class="text">
<span><input type="checkbox" id="action-toggle"></span>
</div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable">
<div class='text'><span>ID</span></div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable">
<div class='text'><span>Created</span></div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable">
<div class='text'><span>Enqueued</span></div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable sorted {{ sort_direction }}">
<div class="sortoptions">
{% if sort_direction == 'ascending' %}
<a href="?desc=1" class="toggle ascending" title="Toggle sorting"></a>
{% else %}
<a href="?desc=0" class="toggle descending" title="Toggle sorting"></a>
{% endif %}
</div>
<div class='text'>
{% if sort_direction == 'ascending' %}
<a href="?desc=1">
{% else %}
<a href="?desc=0">
{% endif %}
Ended
</a>
</div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable">
<div class='text'><span>Status</span></div>
<div class="clear"></div>
</th>
<th scope="col" class="sortable">
<div class='text'><span>Callable</span></div>
<div class="clear"></div>
</th>
{% block extra_columns %}
{% endblock extra_columns %}
</tr>
</thead>
<tbody>
{% for job in jobs %}
<tr>
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="{{ job.id }}">
</td>
<th>
<a href="{% url 'rq_job_detail' queue_index job.id %}">
{{ job.id }}
</a>
</th>
<td>
{% if job.created_at %}
{{ job.created_at|to_localtime|date:"Y-m-d, H:i:s" }}
{% endif %}
</td>
{% if job_status == 'Scheduled' %}
<td>
{% if job.scheduled_at %}
{{ job.scheduled_at|to_localtime|date:"Y-m-d, H:i:s" }}
{% endif %}
</td>
{% endif %}
<td>
{% if job.enqueued_at %}
{{ job.enqueued_at|to_localtime|date:"Y-m-d, H:i:s" }}
{% endif %}
</td>
<td>
{% if job.ended_at %}
{{ job.ended_at|to_localtime|date:"Y-m-d, H:i:s" }}
{% endif %}
</td>
<td>{{ job.get_status.value }}</td>
<td>{{ job|show_func_name }}</td>
{% block extra_columns_values %}
{% endblock extra_columns_values %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p class="paginator">
{% for p in page_range %}
{% if p == page %}
<span class="this-page">{{ p }}</span>
{% elif forloop.last %}
<a href="?page={{ p }}" class="end">{{ p }}</a>
{% else %}
<a href="?page={{ p }}">{{ p }}</a>
{% endif %}
{% endfor %}
{{ num_jobs }} jobs
</p>
</form>
</div>
</div>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion django_rq/templates/django_rq/job_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<div>
<div class = "flex-container">
<label>Status:</label>
<div class="readonly">{{ job.get_status }}</div>
<div class="readonly">{{ job.get_status.value }}</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion django_rq/templates/django_rq/jobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
{{ job.ended_at|to_localtime|date:"Y-m-d, H:i:s" }}
{% endif %}
</td>
<td>{{ job.get_status }}</td>
<td>{{ job.get_status.value }}</td>
<td>{{ job|show_func_name }}</td>
{% block extra_columns_values %}
{% endblock extra_columns_values %}
Expand Down
11 changes: 9 additions & 2 deletions django_rq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,19 @@ def failed_jobs(request, queue_index):
items_per_page = 100
num_jobs = len(registry)
page = int(request.GET.get('page', 1))

if request.GET.get('desc', '1') == '1':
sort_direction = 'descending'
else:
sort_direction = 'ascending'

jobs = []

if num_jobs > 0:
last_page = int(ceil(num_jobs / items_per_page))
page_range = list(range(1, last_page + 1))
offset = items_per_page * (page - 1)
job_ids = registry.get_job_ids(offset, offset + items_per_page - 1, desc=True)
job_ids = registry.get_job_ids(offset, offset + items_per_page - 1, desc=sort_direction == 'descending')
jobs = get_jobs(queue, job_ids, registry)

else:
Expand All @@ -149,8 +155,9 @@ def failed_jobs(request, queue_index):
'page': page,
'page_range': page_range,
'job_status': 'Failed',
'sort_direction': sort_direction,
}
return render(request, 'django_rq/jobs.html', context_data)
return render(request, 'django_rq/failed_jobs.html', context_data)


@never_cache
Expand Down

0 comments on commit 9722a96

Please sign in to comment.