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_timeas max_duration, submit_time, canceled,
16
14
start_time, statusas is_success, reasonas 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_donewhere owner= session_user
19
17
UNION
20
18
SELECT
21
19
id, node, name, comments, atas run_after,
@@ -24,7 +22,7 @@ CREATE VIEW job_status AS
24
22
max_run_timeas 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 ONLYschedule .at_jobs_process where owner= session_user
25
+ FROM ONLY@extschema@ .at_jobs_processwhere owner= session_user
28
26
UNION
29
27
SELECT
30
28
id, node, name, comments, atas 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 ONLYschedule .at_jobs_submitted where owner= session_user ;
35
+ FROM ONLY@extschema@ .at_jobs_submittedwhere 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_timeas max_duration, submit_time, canceled,
45
43
start_time, statusas is_success, reasonas 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, atas run_after,
@@ -53,7 +51,7 @@ CREATE VIEW all_job_status AS
53
51
max_run_timeas 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 ONLYschedule .at_jobs_process
54
+ FROM ONLY@extschema@ .at_jobs_process
57
55
UNION
58
56
SELECT
59
57
id, node, name, comments, atas 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 ONLYschedule .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 WHENl .status THEN
98
+ ' done' ::@extschema@.job_status_t
99
+ ELSE
100
+ ' error' ::@extschema@.job_status_t
101
+ ENDas status,
102
+ l .message as message
103
+
104
+ FROM @extschema@.logas lLEFT OUTER JOIN @extschema@.cronas cON 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 WHENl .status THEN
129
+ ' done' ::@extschema@.job_status_t
130
+ ELSE
131
+ ' error' ::@extschema@.job_status_t
132
+ ENDas status,
133
+ l .message as message
134
+ FROM logas l, cronas cWHERE c .executor = session_user AND c .id = l .cron ;
135
+
136
+
137
+ CREATE FUNCTION get_log (usenametext ) RETURNS
138
+ table(
139
+ cronint ,
140
+ nodetext ,
141
+ scheduled_attimestamp with time zone ,
142
+ nametext ,
143
+ commentstext ,
144
+ commandstext [],
145
+ run_astext ,
146
+ ownertext ,
147
+ use_same_transactionboolean ,
148
+ startedtimestamp with time zone ,
149
+ last_start_availabletimestamp with time zone ,
150
+ finishedtimestamp with time zone ,
151
+ max_run_time interval,
152
+ onrollbacktext ,
153
+ next_time_statementtext ,
154
+ max_instancesinteger ,
155
+ status @extschema@.job_status_t,
156
+ messagetext
157
+ )
158
+ AS
159
+ $BODY$
160
+ SELECT * FROM @extschema@.all_jobs_logwhere owner= usename;
161
+ $BODY$
162
+ LANGUAGE sql STABLE;
163
+
164
+
165
+
166
+ CREATE FUNCTION get_log () RETURNS
167
+ table(
168
+ cronint ,
169
+ nodetext ,
170
+ scheduled_attimestamp with time zone ,
171
+ nametext ,
172
+ commentstext ,
173
+ commandstext [],
174
+ run_astext ,
175
+ ownertext ,
176
+ use_same_transactionboolean ,
177
+ startedtimestamp with time zone ,
178
+ last_start_availabletimestamp with time zone ,
179
+ finishedtimestamp with time zone ,
180
+ max_run_time interval,
181
+ onrollbacktext ,
182
+ next_time_statementtext ,
183
+ max_instancesinteger ,
184
+ status @extschema@.job_status_t,
185
+ messagetext
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
+ cronint ,
197
+ nodetext ,
198
+ scheduled_attimestamp with time zone ,
199
+ nametext ,
200
+ commentstext ,
201
+ commandstext [],
202
+ run_astext ,
203
+ ownertext ,
204
+ use_same_transactionboolean ,
205
+ startedtimestamp with time zone ,
206
+ last_start_availabletimestamp with time zone ,
207
+ finishedtimestamp with time zone ,
208
+ max_run_time interval,
209
+ onrollbacktext ,
210
+ next_time_statementtext ,
211
+ max_instancesinteger ,
212
+ status @extschema@.job_status_t,
213
+ messagetext
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 ADDPRIMARY KEY (start_at, cron);
224
+ ALTER TABLE @extschema@.log ADDPRIMARY KEY (start_at, cron);
69
225
70
- RESET search_path;