diff --git a/routes/timer.py b/routes/timer.py index 78d7d65..26e686a 100644 --- a/routes/timer.py +++ b/routes/timer.py @@ -25,6 +25,7 @@ CREATE TABLE timer_functions ( next_run TIMESTAMPTZ, last_run TIMESTAMPTZ, enabled BOOLEAN NOT NULL DEFAULT TRUE, + invocation_count INT NOT NULL DEFAULT 0, -- Define the foreign key constraint CONSTRAINT fk_timer_functions_user @@ -107,7 +108,7 @@ CREATE TABLE timer_function_invocations ( timer_function_id INT NOT NULL, status TEXT, invocation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(), - logs TEXT, + logs JSONB, version_number INT NOT NULL, CONSTRAINT fk_timer_function_invocations @@ -116,6 +117,23 @@ CREATE TABLE timer_function_invocations ( 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) => { @@ -439,4 +457,3 @@ def history(function_id): return render_block(environment, 'dashboard/timer_functions/history.html', 'page', **args) return render_template('dashboard/timer_functions/history.html', **args) -