Skip to content

Commit 0b1a087

Browse files
author
Vladimir Ershov
committed
VIEWS for AT jobs
1 parent 76a2ee6 commit 0b1a087

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

pgpro_scheduler--2.0.sql

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
CREATE SCHEMA IF NOT EXISTS schedule;
44
SET search_path TO schedule;
55

6-
CREATE TYPE job_status AS ENUM ('working', 'done', 'error');
6+
CREATE TYPE job_status_t AS ENUM ('working', 'done', 'error');
7+
CREATE TYPE job_at_status_t AS ENUM ('submitted', 'processing', 'done');
78

89
CREATE TABLE at_jobs_submitted(
910
id SERIAL PRIMARY KEY,
@@ -138,7 +139,7 @@ CREATE TYPE cron_job AS(
138139
onrollback text, -- statement on ROLLBACK
139140
next_time_statement text, -- statement to calculate next start time
140141
max_instances int, -- the number of instances run at the same time
141-
status job_status, -- status of job
142+
status job_status_t, -- status of job
142143
message text -- error message if one
143144
);
144145

@@ -1272,12 +1273,75 @@ BEFORE DELETE ON cron
12721273
CREATE TRIGGER cron_update_trigger
12731274
AFTER UPDATE ON cron
12741275
FOR EACH ROW EXECUTE PROCEDURE on_cron_update();
1276+
1277+
----------
1278+
-- VIEW --
1279+
----------
1280+
1281+
CREATE VIEW job_status AS
1282+
SELECT
1283+
id, node, name, comments, at as run_after,
1284+
do_sql as query, params, depends_on, executor as run_as, attempt,
1285+
resubmit_limit, postpone as max_wait_interval,
1286+
max_run_time as max_duration, submit_time,
1287+
start_time, status as is_success, reason as error, done_time,
1288+
'done'::job_at_status_t status
1289+
FROM schedule.at_jobs_done where owner = session_user
1290+
UNION
1291+
SELECT
1292+
id, node, name, comments, at as run_after,
1293+
do_sql as query, params, depends_on, executor as run_as, attempt,
1294+
resubmit_limit, postpone as max_wait_interval,
1295+
max_run_time as max_duration, submit_time, start_time,
1296+
NULL as is_success, NULL as error, NULL as done_time,
1297+
'processing'::job_at_status_t status
1298+
FROM ONLY schedule.at_jobs_process where owner = session_user
1299+
UNION
1300+
SELECT
1301+
id, node, name, comments, at as run_after,
1302+
do_sql as query, params, depends_on, executor as run_as, attempt,
1303+
resubmit_limit, postpone as max_wait_interval,
1304+
max_run_time as max_duration, submit_time,
1305+
NULL as start_time, NULL as is_success, NULL as error,
1306+
NULL as done_time,
1307+
'submitted'::job_at_status_t status
1308+
FROM ONLY schedule.at_jobs_submitted where owner = session_user;
1309+
1310+
CREATE VIEW all_job_status AS
1311+
SELECT
1312+
id, node, name, comments, at as run_after,
1313+
do_sql as query, params, depends_on, executor as run_as, owner,
1314+
attempt, resubmit_limit, postpone as max_wait_interval,
1315+
max_run_time as max_duration, submit_time,
1316+
start_time, status as is_success, reason as error, done_time,
1317+
'processing'::job_at_status_t status
1318+
FROM schedule.at_jobs_done
1319+
UNION
1320+
SELECT
1321+
id, node, name, comments, at as run_after,
1322+
do_sql as query, params, depends_on, executor as run_as, owner,
1323+
attempt, resubmit_limit, postpone as max_wait_interval,
1324+
max_run_time as max_duration, submit_time, start_time,
1325+
NULL as is_success, NULL as error, NULL as done_time,
1326+
'processing'::job_at_status_t status
1327+
FROM ONLY schedule.at_jobs_process
1328+
UNION
1329+
SELECT
1330+
id, node, name, comments, at as run_after,
1331+
do_sql as query, params, depends_on, executor as run_as, owner,
1332+
attempt, resubmit_limit, postpone as max_wait_interval,
1333+
max_run_time as max_duration, submit_time,
1334+
NULL as start_time, NULL as is_success, NULL as error,
1335+
NULL as done_time,
1336+
'submitted'::job_at_status_t status
1337+
FROM ONLY schedule.at_jobs_submitted;
12751338

12761339
-----------
12771340
-- GRANT --
12781341
-----------
12791342

12801343
GRANT USAGE ON SCHEMA schedule TO public;
1344+
GRANT SELECT ON schedule.job_status TO public;
12811345

12821346

12831347
RESET search_path;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy