Enhance timer function tracking with invocation count and log storage
- Add `invocation_count` column to `timer_functions` table - Change `logs` column in `timer_function_invocations` to JSONB type - Create trigger function to automatically increment invocation count on new log entries
This commit is contained in:
@@ -25,6 +25,7 @@ CREATE TABLE timer_functions (
|
|||||||
next_run TIMESTAMPTZ,
|
next_run TIMESTAMPTZ,
|
||||||
last_run TIMESTAMPTZ,
|
last_run TIMESTAMPTZ,
|
||||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
invocation_count INT NOT NULL DEFAULT 0,
|
||||||
|
|
||||||
-- Define the foreign key constraint
|
-- Define the foreign key constraint
|
||||||
CONSTRAINT fk_timer_functions_user
|
CONSTRAINT fk_timer_functions_user
|
||||||
@@ -107,7 +108,7 @@ CREATE TABLE timer_function_invocations (
|
|||||||
timer_function_id INT NOT NULL,
|
timer_function_id INT NOT NULL,
|
||||||
status TEXT,
|
status TEXT,
|
||||||
invocation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
invocation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
logs TEXT,
|
logs JSONB,
|
||||||
version_number INT NOT NULL,
|
version_number INT NOT NULL,
|
||||||
|
|
||||||
CONSTRAINT fk_timer_function_invocations
|
CONSTRAINT fk_timer_function_invocations
|
||||||
@@ -116,6 +117,23 @@ CREATE TABLE timer_function_invocations (
|
|||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION fn_increment_invocation_count()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
UPDATE timer_functions
|
||||||
|
SET invocation_count = invocation_count + 1
|
||||||
|
WHERE id = NEW.timer_function_id;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER tr_increment_invocation_count
|
||||||
|
AFTER INSERT ON timer_function_invocations
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE fn_increment_invocation_count();
|
||||||
'''
|
'''
|
||||||
|
|
||||||
DEFAULT_SCRIPT = """async (req) => {
|
DEFAULT_SCRIPT = """async (req) => {
|
||||||
@@ -439,4 +457,3 @@ def history(function_id):
|
|||||||
return render_block(environment, 'dashboard/timer_functions/history.html', 'page', **args)
|
return render_block(environment, 'dashboard/timer_functions/history.html', 'page', **args)
|
||||||
return render_template('dashboard/timer_functions/history.html', **args)
|
return render_template('dashboard/timer_functions/history.html', **args)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user