Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Status: submissions limit removed #1562

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apps/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
path('search', views.SearchView.as_view(), name="search"),
path('organize', views.OrganizeView.as_view(), name="organize"),
path('server_status', views.ServerStatusView.as_view(), name="server_status"),
path('monitor_queues', views.MonitorQueuesView.as_view(), name="monitor_queues"),
# path('test', views.CompetitionListTestView.as_view()),
]
29 changes: 23 additions & 6 deletions src/apps/pages/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import timedelta
from django.utils.timezone import now
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.views.generic import TemplateView
from django.db.models import Count, Q

Expand Down Expand Up @@ -55,6 +54,8 @@ class ServerStatusView(TemplateView):
def get_context_data(self, *args, **kwargs):

show_child_submissions = self.request.GET.get('show_child_submissions', False)
page = self.request.GET.get('page', 1)
submissions_per_page = 50

# Get all submissions
qs = Submission.objects.all()
Expand All @@ -73,18 +74,27 @@ def get_context_data(self, *args, **kwargs):
else:
qs = qs.none() # This returns an empty queryset

# Filter for fetching last 2 days submissions
qs = qs.filter(created_when__gte=now() - timedelta(days=2))

# Filter out child submissions i.e. submission has no parent
if not show_child_submissions:
qs = qs.filter(parent__isnull=True)

qs = qs.order_by('-created_when')
qs = qs.select_related('phase__competition', 'owner')

# Paginate the queryset
paginator = Paginator(qs, submissions_per_page)

try:
submissions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver the first page.
submissions = paginator.page(1)
except EmptyPage:
# If page is out of range, deliver last page of results.
submissions = paginator.page(paginator.num_pages)

context = super().get_context_data(*args, **kwargs)
context['submissions'] = qs[:250]
context['submissions'] = submissions
context['show_child_submissions'] = show_child_submissions

for submission in context['submissions']:
Expand All @@ -103,6 +113,9 @@ def get_context_data(self, *args, **kwargs):
# Add submission owner display name
submission.owner_display_name = submission.owner.display_name if submission.owner.display_name else submission.owner.username

context['paginator'] = paginator
context['is_paginated'] = paginator.num_pages > 1

return context

def format_file_size(self, file_size):
Expand All @@ -123,6 +136,10 @@ def format_file_size(self, file_size):
return f"{n:.1f} {units[i]}"


class MonitorQueuesView(TemplateView):
template_name = 'pages/monitor_queues.html'


def page_not_found_view(request, exception):
print(request)
return render(request, '404.html', status=404)
1 change: 1 addition & 0 deletions src/static/stylus/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@import "src/static/stylus/simple_page.styl"
@import "src/static/stylus/toastr.styl"
@import "src/static/stylus/forum.styl"
@import "src/static/stylus/server_status.styl"

19 changes: 19 additions & 0 deletions src/static/stylus/server_status.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.pagination-nav
padding 10px 0
width 100%
margin-bottom 20px
display flex
justify-content center
align-items center
position relative

.float-left
position absolute
left 0

.float-right
position absolute
right 0

.center
text-align center
1 change: 1 addition & 0 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
{# <a class="item" href="#">Customize Codalab</a>#}
<a class="item" href="{% url "pages:server_status" %}">Server Status</a>
{% if request.user.is_staff %}
<a class="item" href="{% url "pages:monitor_queues" %}">Monitor Queues</a>
<a class="item" href="{% url "admin:index" %}">Django Admin</a>
<a class="item" href="{% url "su_login" %}">Change User</a>
<a class="item" href="{% url "analytics:analytics" %}">Analytics</a>
Expand Down
49 changes: 49 additions & 0 deletions src/templates/pages/monitor_queues.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends "base.html" %}
{% load staticfiles %}

{% block extra_head %}
{% endblock %}

{% block content %}
<div class="ui container">
<h1>Monitor queues</h1>
<div id="external_monitors" class="ui two column grid">
<div class="column">
<div class="ui fluid card">
<a class="image" href="{{ RABBITMQ_MANAGEMENT_URL}}" target="_blank">
<img class="ui large image" src="/static/img/RabbitMQ.png">
</a>
<div class="content">
<a class="header" href="{{ RABBITMQ_MANAGEMENT_URL }}" target="_blank">RabbitMQ</a>
<div class="meta">
This page allows admins to view connections, queued messages, message rates, channels,
exchanges, and other administrative features relating to RabbitMQ e.g. Creating users,
adding v-hosts, and creating policies.
</div>
</div>
</div>
</div>
<div class="column">
<div class="ui fluid card">
<a class="image" href="{{ FLOWER_URL }}" target="_blank">
<img class="ui large image" src="/static/img/Flower.png">
</a>
<div class="content">
<a class="header" href="{{ FLOWER_URL }}" target="_blank">Flower</a>
<div class="meta">
Flower is a powerful web-based Celery monitoring tool designed to keep track of our
tasks.
Admins may view the state of which tasks were run, with what arguments, and many more
features. Here you may also view which queues your celery workers are consuming, and the
state of any tasks in them. At last, there is also a great monitoring page for viewing
the
systemic impact of your workers.
</div>
</div>
</div>
</div>
</div>
</div>


{% endblock %}
61 changes: 22 additions & 39 deletions src/templates/pages/server_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% block content %}
<div class="ui container">
<h1>Recent submissions (up to 250 or 2 days old)</h1>
<h1>Recent Submissions</h1>
<label>
<input type="checkbox" id="show_child_checkbox" {% if show_child_submissions %}checked{% endif %}> Show child submissions
</label>
Expand Down Expand Up @@ -55,48 +55,31 @@ <h1>Recent submissions (up to 250 or 2 days old)</h1>
</tbody>
</table>

<!-- Pagination Div -->
{% if is_paginated %}
<div class="pagination-nav">
{% if submissions.has_previous %}
<span class="float-left">
<a class="ui button" href="?page=1{% if show_child_submissions %}&show_child_submissions={{ show_child_submissions }}{% endif %}">First</a>
<a class="ui button" href="?page={{ submissions.previous_page_number }}{% if show_child_submissions %}&show_child_submissions={{ show_child_submissions }}{% endif %}">Previous</a>
</span>
{% endif %}

<span class="center">
Page {{ submissions.number }} of {{ paginator.num_pages }}
</span>


{% if submissions.has_next %}
<span class="float-right">
<a class="ui button" href="?page={{ submissions.next_page_number }}{% if show_child_submissions %}&show_child_submissions={{ show_child_submissions }}{% endif %}">Next</a>
<a class="ui button" href="?page={{ paginator.num_pages }}{% if show_child_submissions %}&show_child_submissions={{ show_child_submissions }}{% endif %}">Last</a>
</span>
{% endif %}

{% if user.is_superuser %}
<h1>Monitor queues</h1>
<div id="external_monitors" class="ui two column grid">
<div class="column">
<div class="ui fluid card">
<a class="image" href="{{ RABBITMQ_MANAGEMENT_URL}}" target="_blank">
<img class="ui large image" src="/static/img/RabbitMQ.png">
</a>
<div class="content">
<a class="header" href="{{ RABBITMQ_MANAGEMENT_URL }}" target="_blank">RabbitMQ</a>
<div class="meta">
This page allows admins to view connections, queued messages, message rates, channels,
exchanges, and other administrative features relating to RabbitMQ e.g. Creating users,
adding v-hosts, and creating policies.
</div>
</div>
</div>
</div>
<div class="column">
<div class="ui fluid card">
<a class="image" href="{{ FLOWER_URL }}" target="_blank">
<img class="ui large image" src="/static/img/Flower.png">
</a>
<div class="content">
<a class="header" href="{{ FLOWER_URL }}" target="_blank">Flower</a>
<div class="meta">
Flower is a powerful web-based Celery monitoring tool designed to keep track of our
tasks.
Admins may view the state of which tasks were run, with what arguments, and many more
features. Here you may also view which queues your celery workers are consuming, and the
state of any tasks in them. At last, there is also a great monitoring page for viewing
the
systemic impact of your workers.
</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>

<script>
document.addEventListener("DOMContentLoaded", function() {
const checkbox = document.getElementById("show_child_checkbox");
Expand Down