|
3 | 3 | CREATE SCHEMA IF NOT EXISTS schedule;
|
4 | 4 | SET search_path TO schedule;
|
5 | 5 |
|
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'); |
7 | 8 |
|
8 | 9 | CREATE TABLE at_jobs_submitted(
|
9 | 10 | id SERIAL PRIMARY KEY,
|
@@ -138,7 +139,7 @@ CREATE TYPE cron_job AS(
|
138 | 139 | onrollback text, -- statement on ROLLBACK
|
139 | 140 | next_time_statement text, -- statement to calculate next start time
|
140 | 141 | 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 |
142 | 143 | message text -- error message if one
|
143 | 144 | );
|
144 | 145 |
|
@@ -1272,12 +1273,75 @@ BEFORE DELETE ON cron
|
1272 | 1273 | CREATE TRIGGER cron_update_trigger
|
1273 | 1274 | AFTER UPDATE ON cron
|
1274 | 1275 | 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; |
1275 | 1338 |
|
1276 | 1339 | -----------
|
1277 | 1340 | -- GRANT --
|
1278 | 1341 | -----------
|
1279 | 1342 |
|
1280 | 1343 | GRANT USAGE ON SCHEMA schedule TO public;
|
| 1344 | +GRANT SELECT ON schedule.job_status TO public; |
1281 | 1345 |
|
1282 | 1346 |
|
1283 | 1347 | RESET search_path;
|
0 commit comments