1
- SET search_path TO schedule;
2
-
3
1
DROP VIEW job_status;
4
2
DROP VIEW all_job_status;
5
3
@@ -15,7 +13,7 @@ CREATE VIEW job_status AS
15
13
max_run_time as max_duration, submit_time, canceled,
16
14
start_time, status as is_success, reason as error, done_time,
17
15
' done' ::job_at_status_t status
18
- FROM schedule .at_jobs_done where owner = session_user
16
+ FROM @extschema@ .at_jobs_done where owner = session_user
19
17
UNION
20
18
SELECT
21
19
id, node, name, comments, at as run_after,
@@ -24,7 +22,7 @@ CREATE VIEW job_status AS
24
22
max_run_time as max_duration, submit_time, canceled, start_time,
25
23
NULL as is_success, NULL as error, NULL as done_time,
26
24
' processing' ::job_at_status_t status
27
- FROM ONLY schedule .at_jobs_process where owner = session_user
25
+ FROM ONLY @extschema@ .at_jobs_process where owner = session_user
28
26
UNION
29
27
SELECT
30
28
id, node, name, comments, at as run_after,
@@ -34,7 +32,7 @@ CREATE VIEW job_status AS
34
32
NULL as start_time, NULL as is_success, NULL as error,
35
33
NULL as done_time,
36
34
' submitted' ::job_at_status_t status
37
- FROM ONLY schedule .at_jobs_submitted where owner = session_user ;
35
+ FROM ONLY @extschema@ .at_jobs_submitted where owner = session_user ;
38
36
39
37
CREATE VIEW all_job_status AS
40
38
SELECT
@@ -44,7 +42,7 @@ CREATE VIEW all_job_status AS
44
42
max_run_time as max_duration, submit_time, canceled,
45
43
start_time, status as is_success, reason as error, done_time,
46
44
' done' ::job_at_status_t status
47
- FROM schedule .at_jobs_done
45
+ FROM @extschema@ .at_jobs_done
48
46
UNION
49
47
SELECT
50
48
id, node, name, comments, at as run_after,
@@ -53,7 +51,7 @@ CREATE VIEW all_job_status AS
53
51
max_run_time as max_duration, submit_time, canceled, start_time,
54
52
NULL as is_success, NULL as error, NULL as done_time,
55
53
' processing' ::job_at_status_t status
56
- FROM ONLY schedule .at_jobs_process
54
+ FROM ONLY @extschema@ .at_jobs_process
57
55
UNION
58
56
SELECT
59
57
id, node, name, comments, at as run_after,
@@ -63,8 +61,165 @@ CREATE VIEW all_job_status AS
63
61
NULL as start_time, NULL as is_success, NULL as error,
64
62
NULL as done_time,
65
63
' submitted' ::job_at_status_t status
66
- FROM ONLY schedule .at_jobs_submitted ;
64
+ FROM ONLY @extschema@.at_jobs_submitted;
65
+
66
+ GRANT SELECT ON @extschema@.job_status TO public;
67
+
68
+ DROP FUNCTION get_log();
69
+ DROP FUNCTION get_log(text );
70
+ DROP FUNCTION get_user_log();
71
+
72
+
73
+ CREATE INDEX ON cron (owner);
74
+ CREATE INDEX ON cron (executor);
75
+
76
+ --
77
+ -- show all scheduled jobs
78
+ --
79
+ CREATE VIEW all_jobs_log AS
80
+ SELECT
81
+ coalesce(c .id , l .cron ) as cron,
82
+ c .node as node,
83
+ l .start_at as scheduled_at,
84
+ coalesce(c .name , ' --DELETED--' ) as name,
85
+ c .comments as comments,
86
+ c .do_sql as commands,
87
+ c .executor as run_as,
88
+ c .owner as owner,
89
+ c .same_transaction as use_same_transaction,
90
+ l .started as started,
91
+ l .last_start_available as last_start_available,
92
+ l .finished as finished,
93
+ c .max_run_time as max_run_time,
94
+ c .onrollback_statement as onrollback,
95
+ c .next_time_statement as next_time_statement,
96
+ c .max_instances as max_instances,
97
+ CASE WHEN l .status THEN
98
+ ' done' ::@extschema@.job_status_t
99
+ ELSE
100
+ ' error' ::@extschema@.job_status_t
101
+ END as status,
102
+ l .message as message
103
+
104
+ FROM @extschema@.log as l LEFT OUTER JOIN @extschema@.cron as c ON c .id = l .cron ;
105
+
106
+ --
107
+ -- show scheduled jobs of session user
108
+ --
109
+
110
+ CREATE VIEW jobs_log AS
111
+ SELECT
112
+ coalesce(c .id , l .cron ) as cron,
113
+ c .node as node,
114
+ l .start_at as scheduled_at,
115
+ coalesce(c .name , ' --DELETED--' ) as name,
116
+ c .comments as comments,
117
+ c .do_sql as commands,
118
+ c .executor as run_as,
119
+ c .owner as owner,
120
+ c .same_transaction as use_same_transaction,
121
+ l .started as started,
122
+ l .last_start_available as last_start_available,
123
+ l .finished as finished,
124
+ c .max_run_time as max_run_time,
125
+ c .onrollback_statement as onrollback,
126
+ c .next_time_statement as next_time_statement,
127
+ c .max_instances as max_instances,
128
+ CASE WHEN l .status THEN
129
+ ' done' ::@extschema@.job_status_t
130
+ ELSE
131
+ ' error' ::@extschema@.job_status_t
132
+ END as status,
133
+ l .message as message
134
+ FROM log as l, cron as c WHERE c .executor = session_user AND c .id = l .cron ;
135
+
136
+
137
+ CREATE FUNCTION get_log (usename text ) RETURNS
138
+ table(
139
+ cron int ,
140
+ node text ,
141
+ scheduled_at timestamp with time zone ,
142
+ name text ,
143
+ comments text ,
144
+ commands text [],
145
+ run_as text ,
146
+ owner text ,
147
+ use_same_transaction boolean ,
148
+ started timestamp with time zone ,
149
+ last_start_available timestamp with time zone ,
150
+ finished timestamp with time zone ,
151
+ max_run_time interval,
152
+ onrollback text ,
153
+ next_time_statement text ,
154
+ max_instances integer ,
155
+ status @extschema@.job_status_t,
156
+ message text
157
+ )
158
+ AS
159
+ $BODY$
160
+ SELECT * FROM @extschema@.all_jobs_log where owner = usename;
161
+ $BODY$
162
+ LANGUAGE sql STABLE;
163
+
164
+
165
+
166
+ CREATE FUNCTION get_log () RETURNS
167
+ table(
168
+ cron int ,
169
+ node text ,
170
+ scheduled_at timestamp with time zone ,
171
+ name text ,
172
+ comments text ,
173
+ commands text [],
174
+ run_as text ,
175
+ owner text ,
176
+ use_same_transaction boolean ,
177
+ started timestamp with time zone ,
178
+ last_start_available timestamp with time zone ,
179
+ finished timestamp with time zone ,
180
+ max_run_time interval,
181
+ onrollback text ,
182
+ next_time_statement text ,
183
+ max_instances integer ,
184
+ status @extschema@.job_status_t,
185
+ message text
186
+ )
187
+ AS
188
+ $BODY$
189
+ SELECT * FROM @extschema@.all_jobs_log;
190
+ $BODY$
191
+ LANGUAGE sql STABLE;
192
+
193
+
194
+ CREATE FUNCTION get_user_log () RETURNS
195
+ table(
196
+ cron int ,
197
+ node text ,
198
+ scheduled_at timestamp with time zone ,
199
+ name text ,
200
+ comments text ,
201
+ commands text [],
202
+ run_as text ,
203
+ owner text ,
204
+ use_same_transaction boolean ,
205
+ started timestamp with time zone ,
206
+ last_start_available timestamp with time zone ,
207
+ finished timestamp with time zone ,
208
+ max_run_time interval,
209
+ onrollback text ,
210
+ next_time_statement text ,
211
+ max_instances integer ,
212
+ status @extschema@.job_status_t,
213
+ message text
214
+ )
215
+ AS
216
+ $BODY$
217
+ SELECT * FROM @extschema@.jobs_log;
218
+ $BODY$
219
+ LANGUAGE sql STABLE;
220
+
221
+ GRANT SELECT ON @extschema@.jobs_log TO public;
67
222
68
- GRANT SELECT ON schedule .job_status TO public;
223
+ ALTER TABLE @extschema@.at ADD PRIMARY KEY (start_at, cron);
224
+ ALTER TABLE @extschema@.log ADD PRIMARY KEY (start_at, cron);
69
225
70
- RESET search_path;
0 commit comments