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

Cron Jobs listing #46

Merged
merged 4 commits into from
Jun 3, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Cron Jobs (Tasks) listing support

### Changed

Expand Down
22 changes: 22 additions & 0 deletions src/appier_extras/parts/admin/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def routes(self):
(("GET",), "/admin/sessions/<str:sid>/delete", self.delete_session),
(("GET",), "/admin/peers", self.list_peers),
(("GET",), "/admin/counters", self.list_counters),
(("GET",), "/admin/cron_jobs", self.list_cron_jobs),
(("GET",), "/admin/events.csv", self.list_events_csv),
(("GET",), "/admin/locale.csv", self.list_locales_csv),
(
Expand Down Expand Up @@ -1466,6 +1467,13 @@ def list_counters(self):
counters = collection.find()
return self.template("counters.html.tpl", section="status", counters=counters)

@appier.ensure(token="admin.status", context="admin")
def list_cron_jobs(self):
cron_jobs = self._cron_jobs()
return self.template(
"cron_jobs.html.tpl", section="status", cron_jobs=cron_jobs
)

@appier.ensure(token="admin", context="admin")
def list_events_csv(self):
object = appier.get_object(alias=True, find=True, limit=0)
Expand Down Expand Up @@ -2443,6 +2451,20 @@ def _counters(self):
collection = adapter.collection("counters")
return collection

def _cron_jobs(self):
if not hasattr(self.owner, "_cron"):
return []
if not self.owner._cron:
return []
return [task[1] for task in self.owner._cron._tasks]

def _cron_jobs_count(self):
if not hasattr(self.owner, "_cron"):
return 0
if not self.owner._cron:
return 0
return len(self.owner._cron._tasks)

def _appier_extras_loader(self, module):
versions = []
if hasattr(module, "VERSION"):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "admin/admin.fluid.html.tpl" %}
{% block title %}Counters{% endblock %}
{% block name %}Counter{% endblock %}
{% block name %}Counters{% endblock %}
{% block style %}no-padding{% endblock %}
{% block content %}
<table class="filter no-fixed" data-no_input="1">
Expand Down
28 changes: 28 additions & 0 deletions src/appier_extras/parts/admin/templates/fluid/cron_jobs.html.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "admin/admin.fluid.html.tpl" %}
{% block title %}Cron Jobs{% endblock %}
{% block name %}Cron Jobs{% endblock %}
{% block style %}no-padding{% endblock %}
{% block content %}
<table class="filter no-fixed" data-no_input="1">
<thead>
<tr class="table-row table-header">
<th class="text-left">Identifier</th>
<th class="text-left">Description</th>
<th class="text-left">Cron</th>
<th class="text-left">Next Run</th>
</tr>
</thead>
<tbody class="filter-contents">
{% for cron_job in cron_jobs %}
<tr class="table-row">
<td class="text-left">
<strong>{{ cron_job.id }}</strong>
</td>
<td class="text-left">{{ cron_job.description|default("-", True) }}</td>
<td class="text-left">{{ cron_job.cron }}</td>
<td class="text-left">{{ cron_job.next_run() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
7 changes: 7 additions & 0 deletions src/appier_extras/parts/admin/templates/fluid/status.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{% set sessions_c = request.session_c.count() %}
{% set peers_c = own._peers|length %}
{% set counters_c = own._counters().count() %}
{% set cron_jobs_c = own._cron_jobs_count() %}
<div class="show-panel">
<div class="panel-header">
<img class="image square no-border" src="{{ own.logo_square_url or url_for('admin', filename = 'images/logo_96.png') }}" />
Expand Down Expand Up @@ -102,6 +103,12 @@
<a href="{{ url_for('admin.list_counters') }}">{{ counters_c }} {% if counters_c == 1 %}counter{% else %}counters{% endif %}</a>
</dd>
</div>
<div class="item">
<dt>Cron Jobs</dt>
<dd>
<a href="{{ url_for('admin.list_cron_jobs') }}">{{ cron_jobs_c }} {% if cron_jobs_c == 1 %}job{% else %}jobs{% endif %}</a>
</dd>
</div>
<div class="item">
<dt>Cache class</dt>
<dd>{{ own.cache_c.__name__ }}</dd>
Expand Down