Skip to content

Commit

Permalink
Add timescaledb_information.jobs view
Browse files Browse the repository at this point in the history
This patch adds a convenience view to list all configured jobs.
  • Loading branch information
svenklemm committed Sep 21, 2020
1 parent c321fe0 commit 9ed30a0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
17 changes: 17 additions & 0 deletions sql/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ CREATE OR REPLACE VIEW timescaledb_information.policy_stats as
INNER JOIN _timescaledb_internal.bgw_job_stat js on j.id = js.job_id
ORDER BY ht.schema_name, ht.table_name;

-- view for background worker jobs
CREATE OR REPLACE VIEW timescaledb_information.jobs AS
SELECT j.id AS job_id,
j.application_name,
j.schedule_interval,
j.max_runtime,
j.max_retries,
j.retry_period,
j.proc_schema,
j.proc_name,
j.owner,
j.scheduled,
j.config,
js.next_start
FROM _timescaledb_config.bgw_job j
LEFT JOIN _timescaledb_internal.bgw_job_stat js ON js.job_id = j.id;

-- views for continuous aggregate queries ---
CREATE OR REPLACE VIEW timescaledb_information.continuous_aggregates as
SELECT format('%1$I.%2$I', cagg.user_view_schema, cagg.user_view_name)::regclass as view_name,
Expand Down
3 changes: 2 additions & 1 deletion test/expected/pg_dump.out
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
timescaledb_information.chunks
timescaledb_information.data_node
timescaledb_information.continuous_aggregates
timescaledb_information.jobs
timescaledb_information.policy_stats
timescaledb_information.license
timescaledb_information.hypertables
Expand All @@ -549,7 +550,7 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
_timescaledb_internal.bgw_policy_chunk_stats
_timescaledb_internal.bgw_job_stat
_timescaledb_catalog.tablespace_id_seq
(14 rows)
(15 rows)

-- Make sure we can't run our restoring functions as a normal perm user as that would disable functionality for the whole db
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
Expand Down
17 changes: 17 additions & 0 deletions tsl/test/expected/bgw_custom.out
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ SELECT add_job('custom_func_definer', '1h', config:='{"type":"function"}'::jsonb
1004
(1 row)

SELECT * FROM timescaledb_information.jobs ORDER BY 1;
job_id | application_name | schedule_interval | max_runtime | max_retries | retry_period | proc_schema | proc_name | owner | scheduled | config | next_start
--------+------------------------+-------------------+-----------------+-------------+--------------+-----------------------+---------------------+-------------------+-----------+-----------------------+------------
1 | Telemetry Reporter [1] | @ 24 hours | @ 1 min 40 secs | -1 | @ 1 hour | _timescaledb_internal | policy_telemetry | super_user | t | |
1000 | Custom Job [1000] | @ 1 hour | @ 0 | -1 | @ 5 mins | public | custom_func | default_perm_user | t | {"type": "function"} |
1001 | Custom Job [1001] | @ 1 hour | @ 0 | -1 | @ 5 mins | public | custom_proc | default_perm_user | t | {"type": "procedure"} |
1002 | Custom Job [1002] | @ 1 hour | @ 0 | -1 | @ 5 mins | public | custom_proc2 | default_perm_user | t | {"type": "procedure"} |
1003 | Custom Job [1003] | @ 1 hour | @ 0 | -1 | @ 5 mins | public | custom_func | default_perm_user | t | {"type": "function"} |
1004 | Custom Job [1004] | @ 1 hour | @ 0 | -1 | @ 5 mins | public | custom_func_definer | default_perm_user | t | {"type": "function"} |
(6 rows)

CALL run_job(1000);
CALL run_job(1001);
CALL run_job(1002);
Expand Down Expand Up @@ -108,6 +119,12 @@ SELECT * FROM _timescaledb_config.bgw_job WHERE id >= 1000;
----+------------------+-------------------+-------------+-------------+--------------+-------------+-----------+-------+-----------+---------------+--------
(0 rows)

SELECT count(*) FROM timescaledb_information.jobs WHERE job_id >= 1000;
count
-------
0
(1 row)

\c :TEST_DBNAME :ROLE_SUPERUSER
-- test altering job with NULL config
SELECT job_id FROM alter_job(1,scheduled:=false);
Expand Down
3 changes: 3 additions & 0 deletions tsl/test/sql/bgw_custom.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ SELECT add_job('custom_proc2','1h', config:= '{"type":"procedure"}'::jsonb);
SELECT add_job('custom_func', '1h', config:='{"type":"function"}'::jsonb);
SELECT add_job('custom_func_definer', '1h', config:='{"type":"function"}'::jsonb);

SELECT * FROM timescaledb_information.jobs ORDER BY 1;

CALL run_job(1000);
CALL run_job(1001);
CALL run_job(1002);
Expand All @@ -55,6 +57,7 @@ SELECT delete_job(1004);

-- check jobs got removed
SELECT * FROM _timescaledb_config.bgw_job WHERE id >= 1000;
SELECT count(*) FROM timescaledb_information.jobs WHERE job_id >= 1000;

\c :TEST_DBNAME :ROLE_SUPERUSER
-- test altering job with NULL config
Expand Down

0 comments on commit 9ed30a0

Please sign in to comment.