1- SET search_path TO schedule;
2-
31DROP VIEW job_status;
42DROP VIEW all_job_status;
53
@@ -15,7 +13,7 @@ CREATE VIEW job_status AS
1513max_run_timeas max_duration, submit_time, canceled,
1614start_time, statusas is_success, reasonas error, done_time,
1715' 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
1917UNION
2018SELECT
2119id, node, name, comments, atas run_after,
@@ -24,7 +22,7 @@ CREATE VIEW job_status AS
2422max_run_timeas max_duration, submit_time, canceled, start_time,
2523NULL as is_success,NULL as error,NULL as done_time,
2624' 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
2826UNION
2927SELECT
3028id, node, name, comments, atas run_after,
@@ -34,7 +32,7 @@ CREATE VIEW job_status AS
3432NULL as start_time,NULL as is_success,NULL as error,
3533NULL as done_time,
3634' 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 ;
3836
3937CREATE VIEW all_job_status AS
4038SELECT
@@ -44,7 +42,7 @@ CREATE VIEW all_job_status AS
4442max_run_timeas max_duration, submit_time, canceled,
4543start_time, statusas is_success, reasonas error, done_time,
4644' done' ::job_at_status_t status
47- FROM schedule .at_jobs_done
45+ FROM @extschema@ .at_jobs_done
4846UNION
4947SELECT
5048id, node, name, comments, atas run_after,
@@ -53,7 +51,7 @@ CREATE VIEW all_job_status AS
5351max_run_timeas max_duration, submit_time, canceled, start_time,
5452NULL as is_success,NULL as error,NULL as done_time,
5553' processing' ::job_at_status_t status
56- FROM ONLYschedule .at_jobs_process
54+ FROM ONLY@extschema@ .at_jobs_process
5755UNION
5856SELECT
5957id, node, name, comments, atas run_after,
@@ -63,8 +61,165 @@ CREATE VIEW all_job_status AS
6361NULL as start_time,NULL as is_success,NULL as error,
6462NULL as done_time,
6563' 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;
67222
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);
69225
70- RESET search_path;