Skip to content

Commit 806748a

Browse files
committed
[+] add more job control functions
- `timetable.pause_job()` - `timetable.resume_job()`
1 parent 12e9a8d commit 806748a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

internal/pgengine/sql/job_functions.sql

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ $$ LANGUAGE SQL;
125125

126126
COMMENT ON FUNCTION timetable.move_task_down IS 'Switch the order of the task execution with a following task within the chain';
127127

128+
-- delete_task() will delete the task from a chain
129+
CREATE OR REPLACE FUNCTION timetable.delete_task(IN task_id BIGINT) RETURNS boolean AS $$
130+
WITH del_task AS (DELETE FROM timetable.task WHERE task_id = $1 RETURNING task_id)
131+
SELECT EXISTS(SELECT 1 FROM del_task)
132+
$$ LANGUAGE SQL;
133+
134+
COMMENT ON FUNCTION timetable.delete_task IS 'Delete the task from a chain';
135+
128136
-- delete_job() will delete the chain and its tasks from the system
129137
CREATE OR REPLACE FUNCTION timetable.delete_job(IN job_name TEXT) RETURNS boolean AS $$
130138
WITH del_chain AS (DELETE FROM timetable.chain WHERE chain.chain_name = $1 RETURNING chain_id)
@@ -133,10 +141,18 @@ $$ LANGUAGE SQL;
133141

134142
COMMENT ON FUNCTION timetable.delete_job IS 'Delete the chain and its tasks from the system';
135143

136-
-- delete_task() will delete the task from a chain
137-
CREATE OR REPLACE FUNCTION timetable.delete_task(IN task_id BIGINT) RETURNS boolean AS $$
138-
WITH del_task AS (DELETE FROM timetable.task WHERE task_id = $1 RETURNING task_id)
139-
SELECT EXISTS(SELECT 1 FROM del_task)
144+
-- pause_job() will pause the chain (set live = false)
145+
CREATE OR REPLACE FUNCTION timetable.pause_job(IN job_name TEXT) RETURNS boolean AS $$
146+
WITH upd_chain AS (UPDATE timetable.chain SET live = false WHERE chain.chain_name = $1 RETURNING chain_id)
147+
SELECT EXISTS(SELECT 1 FROM upd_chain)
148+
$$ LANGUAGE SQL;
149+
150+
COMMENT ON FUNCTION timetable.pause_job IS 'Pause the chain (set live = false)';
151+
152+
-- resume_job() will resume the chain (set live = true)
153+
CREATE OR REPLACE FUNCTION timetable.resume_job(IN job_name TEXT) RETURNS boolean AS $$
154+
WITH upd_chain AS (UPDATE timetable.chain SET live = true WHERE chain.chain_name = $1 RETURNING chain_id)
155+
SELECT EXISTS(SELECT 1 FROM upd_chain)
140156
$$ LANGUAGE SQL;
141157

142-
COMMENT ON FUNCTION timetable.delete_task IS 'Delete the task from a chain';
158+
COMMENT ON FUNCTION timetable.resume_job IS 'Resume the chain (set live = true)';

0 commit comments

Comments
 (0)