finished_at = Column(DateTime(timezone=False), nullable=False)
+ # Date
+
+ @property
+ def date(self):
+ if self.finished_at:
+ return self.finished_at.date()
+
+ # Fall back on to today
+ return datetime.date.today()
+
# Timeout
timeout = Column(Interval)
-{% extends "../base.html" %}
+{% extends "base.html" %}
-{% block title %}{{ _("Recent Jobs") }}{% end block %}
+{% from "jobs/macros.html" import JobQueue with context %}
+
+{% block title %}{{ _("Recent Jobs") }}{% endblock %}
{% block body %}
<section class="hero is-light">
{{ _("Recently Failed Jobs") }}
{% else %}
{{ _("Recent Jobs") }}
- {% end %}
+ {% endif %}
</h1>
<div class="buttons are-small">
- <a class="button is-danger {% if not failed_only %}is-outlined{% end %}"
- href="{{ make_url("/jobs", offset=max(offset - limit, 0), limit=limit, failed_only=not failed_only) }}">
+ <a class="button is-danger {% if not failed_only %}is-outlined{% endif %}"
+ href="{{ make_url("/jobs", offset=(offset - limit) if (offset - limit) > 0 else 0,
+ limit=limit, failed_only=not failed_only) }}">
{{ _("Failed") }}
</a>
</div>
<section class="section">
<div class="container">
{# Render all jobs #}
- {% for date in jobs %}
+ {% for date, items in jobs | groupby("date") %}
<div class="block">
- <h4 class="title is-4">{{ locale.format_day(date) }}</h4>
+ <h4 class="title is-4">{{ date | format_day }}</h4>
- {% module JobsQueue(jobs[date]) %}
+ {{ JobQueue(items) }}
</div>
- {% end %}
+ {% endfor %}
<div class="block">
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
- <a class="pagination-previous {% if not offset %}is-disabled{% end %}"
+ <a class="pagination-previous {% if not offset %}is-disabled{% endif %}"
href="{{ make_url("/jobs", offset=offset - limit, limit=limit, failed_only=failed_only) }}">
{{ _("Previous Page") }}
</a>
</div>
</div>
</section>
-{% end block %}
+{% endblock %}
# Filter
failed_only = self.get_argument_bool("failed_only")
- with self.db.transaction():
- jobs = self.backend.jobs.get_finished(failed_only=failed_only,
- limit=limit, offset=offset)
-
- # Group jobs by date
- jobs = await misc.group(jobs, lambda job: job.finished_at.date())
-
- self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset,
+ # Fetch all finished jobs
+ jobs = self.backend.jobs.get_finished(
+ failed_only = failed_only,
+ limit = limit,
+ offset = offset,
+ )
+
+ await self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset,
failed_only=failed_only)