Add logs view for timer functions
- Create new database table `timer_function_invocations` to track function executions - Implement `/logs/<function_id>` route in timer routes to fetch and display invocation logs - Add new logs template for timer functions with detailed invocation information - Update header templates to include logs URL for timer functions
This commit is contained in:
@@ -101,6 +101,21 @@ AFTER INSERT OR UPDATE
|
|||||||
ON timer_functions
|
ON timer_functions
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE PROCEDURE fn_timer_functions_versioning();
|
EXECUTE PROCEDURE fn_timer_functions_versioning();
|
||||||
|
|
||||||
|
CREATE TABLE timer_function_invocations (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
timer_function_id INT NOT NULL,
|
||||||
|
status TEXT,
|
||||||
|
invocation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
logs TEXT,
|
||||||
|
version_number INT NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT fk_timer_function_invocations
|
||||||
|
FOREIGN KEY (timer_function_id)
|
||||||
|
REFERENCES timer_functions (id)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
DEFAULT_SCRIPT = """async (req) => {
|
DEFAULT_SCRIPT = """async (req) => {
|
||||||
@@ -353,4 +368,38 @@ def toggle(function_id):
|
|||||||
"message": f"Error toggling timer function: {str(e)}"
|
"message": f"Error toggling timer function: {str(e)}"
|
||||||
}), 400
|
}), 400
|
||||||
|
|
||||||
|
@timer.route('/logs/<int:function_id>')
|
||||||
|
@login_required
|
||||||
|
def logs(function_id):
|
||||||
|
# Fetch the timer function to verify ownership
|
||||||
|
timer_function = db.execute("""
|
||||||
|
SELECT id, name
|
||||||
|
FROM timer_functions
|
||||||
|
WHERE id = %s AND user_id = %s
|
||||||
|
""", [function_id, current_user.id], one=True)
|
||||||
|
|
||||||
|
if not timer_function:
|
||||||
|
flash('Timer function not found', 'error')
|
||||||
|
return redirect(url_for('timer.overview'))
|
||||||
|
|
||||||
|
# Fetch the invocation logs
|
||||||
|
timer_function_invocations = db.execute("""
|
||||||
|
SELECT id, timer_function_id, status, invocation_time,
|
||||||
|
logs, version_number
|
||||||
|
FROM timer_function_invocations
|
||||||
|
WHERE timer_function_id = %s
|
||||||
|
ORDER BY invocation_time DESC
|
||||||
|
LIMIT 100
|
||||||
|
""", [function_id])
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'user_id': current_user.id,
|
||||||
|
'function_id': function_id,
|
||||||
|
'timer_function_invocations': timer_function_invocations
|
||||||
|
}
|
||||||
|
|
||||||
|
if htmx:
|
||||||
|
return render_block(environment, 'dashboard/timer_functions/logs.html', 'page', **args)
|
||||||
|
return render_template('dashboard/timer_functions/logs.html', **args)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ show_logs=True,
|
|||||||
show_client=True,
|
show_client=True,
|
||||||
show_history=True,
|
show_history=True,
|
||||||
edit_url=url_for('http_function_editor', function_id=function_id),
|
edit_url=url_for('http_function_editor', function_id=function_id),
|
||||||
cancel_url=url_for('dashboard_http_functions')) }}
|
cancel_url=url_for('dashboard_http_functions',
|
||||||
|
logs_url=url_for('get_http_function_logs', function_id=function_id))) }}
|
||||||
|
|
||||||
<div class="mx-auto w-full pt-4" id="client-u{{ user_id }}-f{{ function_id }}">
|
<div class="mx-auto w-full pt-4" id="client-u{{ user_id }}-f{{ function_id }}">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ show_logs=True,
|
|||||||
show_client=True,
|
show_client=True,
|
||||||
show_history=True,
|
show_history=True,
|
||||||
edit_url=edit_url,
|
edit_url=edit_url,
|
||||||
cancel_url=cancel_url) }}
|
cancel_url=cancel_url,
|
||||||
|
logs_url=url_for('get_http_function_logs', function_id=function_id)) }}
|
||||||
|
|
||||||
|
|
||||||
<div id="app" class="p-1">
|
<div id="app" class="p-1">
|
||||||
|
|||||||
@@ -26,8 +26,7 @@
|
|||||||
{% if show_logs|default(false, true) %}
|
{% if show_logs|default(false, true) %}
|
||||||
<button
|
<button
|
||||||
class="group flex flex-col items-center {% if active_tab == 'logs' %}text-blue-600{% else %}text-gray-500 hover:text-blue-600{% endif %}"
|
class="group flex flex-col items-center {% if active_tab == 'logs' %}text-blue-600{% else %}text-gray-500 hover:text-blue-600{% endif %}"
|
||||||
hx-get="{{ url_for('get_http_function_logs', function_id=function_id) }}" hx-target="#container"
|
hx-get="{{ logs_url }}" hx-target="#container" hx-swap="innerHTML" hx-push-url="true">
|
||||||
hx-swap="innerHTML" hx-push-url="true">
|
|
||||||
<div
|
<div
|
||||||
class="p-2 rounded-lg {% if active_tab == 'logs' %}bg-blue-50{% else %}group-hover:bg-blue-50{% endif %}">
|
class="p-2 rounded-lg {% if active_tab == 'logs' %}bg-blue-50{% else %}group-hover:bg-blue-50{% endif %}">
|
||||||
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ show_logs=True,
|
|||||||
show_client=True,
|
show_client=True,
|
||||||
show_history=True,
|
show_history=True,
|
||||||
edit_url=url_for('http_function_editor', function_id=function_id),
|
edit_url=url_for('http_function_editor', function_id=function_id),
|
||||||
cancel_url=url_for('dashboard_http_functions')) }}
|
cancel_url=url_for('dashboard_http_functions'),
|
||||||
|
logs_url=url_for('get_http_function_logs', function_id=function_id)) }}
|
||||||
|
|
||||||
<!-- Timeline -->
|
<!-- Timeline -->
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ show_logs=True,
|
|||||||
show_client=True,
|
show_client=True,
|
||||||
show_history=True,
|
show_history=True,
|
||||||
edit_url=url_for('http_function_editor', function_id=function_id),
|
edit_url=url_for('http_function_editor', function_id=function_id),
|
||||||
cancel_url=url_for('dashboard_http_functions')) }}
|
cancel_url=url_for('dashboard_http_functions',
|
||||||
|
logs_url=url_for('get_http_function_logs', function_id=function_id))) }}
|
||||||
|
|
||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
|
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ show_logs=True,
|
|||||||
show_client=False,
|
show_client=False,
|
||||||
show_history=True,
|
show_history=True,
|
||||||
edit_url=url_for('timer.edit', function_id=function_id),
|
edit_url=url_for('timer.edit', function_id=function_id),
|
||||||
cancel_url=url_for('timer.overview')) }}
|
cancel_url=url_for('timer.overview'),
|
||||||
|
logs_url=url_for('timer.logs', function_id=function_id)) }}
|
||||||
|
|
||||||
|
|
||||||
<div id="app" class="p-1">
|
<div id="app" class="p-1">
|
||||||
|
|||||||
72
templates/dashboard/timer_functions/logs.html
Normal file
72
templates/dashboard/timer_functions/logs.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
{% extends 'dashboard.html' %}
|
||||||
|
|
||||||
|
{% block page %}
|
||||||
|
|
||||||
|
{{ render_partial('dashboard/http_functions/header.html', user_id=user_id, function_id=function_id,
|
||||||
|
active_tab='logs',
|
||||||
|
show_edit_form=True,
|
||||||
|
show_logs=True,
|
||||||
|
show_history=True,
|
||||||
|
edit_url=url_for('timer.edit', function_id=function_id),
|
||||||
|
cancel_url=url_for('timer.overview'),
|
||||||
|
logs_url=url_for('timer.logs', function_id=function_id)) }}
|
||||||
|
|
||||||
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||||
|
<div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
|
||||||
|
<!-- Headers -->
|
||||||
|
<div class="grid md:grid-cols-3 gap-4 bg-gray-50 p-4 border-b border-gray-200">
|
||||||
|
<div class="font-semibold text-gray-600 md:block hidden">Invocation Time</div>
|
||||||
|
<div class="font-semibold text-gray-600 md:block hidden">Status</div>
|
||||||
|
<div class="font-semibold text-gray-600 md:block hidden">Logs</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Data Rows -->
|
||||||
|
{% for invocation in timer_function_invocations %}
|
||||||
|
<div
|
||||||
|
class="grid md:grid-cols-3 gap-4 p-4 hover:bg-gray-50 transition-colors duration-150 border-b border-gray-200">
|
||||||
|
<!-- Timestamp -->
|
||||||
|
<div class="flex items-center space-x-2">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-sm text-gray-900">{{ invocation.invocation_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
}}</span>
|
||||||
|
<span
|
||||||
|
class="inline-flex items-center w-fit px-2 py-1 text-xs font-medium bg-blue-100 text-blue-700 rounded-full">
|
||||||
|
v{{ invocation.version_number }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Status -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div
|
||||||
|
class="{{ 'bg-green-100 text-green-700' if invocation.status == 'SUCCESS' else 'bg-red-100 text-red-700' }} px-3 py-1 rounded-full text-sm">
|
||||||
|
{{ invocation.status }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Logs -->
|
||||||
|
<div class="bg-gray-50 rounded-lg p-3 overflow-auto max-h-40">
|
||||||
|
<pre class="text-sm font-mono text-gray-600 whitespace-pre-wrap">{{ invocation.logs }}</pre>
|
||||||
|
{% if not invocation.logs %}
|
||||||
|
<div class="text-sm text-gray-400 italic">No logs available</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if not timer_function_invocations %}
|
||||||
|
<div class="p-8 text-center">
|
||||||
|
<div class="text-gray-400">
|
||||||
|
<svg class="mx-auto h-12 w-12" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<h3 class="mt-2 text-sm font-medium text-gray-900">No logs found</h3>
|
||||||
|
<p class="mt-1 text-sm text-gray-500">No timer function invocations have been recorded yet.</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user