Creating procedures for actions

The signature for actions is (job_id INT, config JSONB). It can either be implemented as function or procedure. The content of the config JSONB is completely up to the job and may also be NULL if no parameters are required.

This is a generic template for a procedure that works with User Defined Actions.

CREATE OR REPLACE PROCEDURE user_defined_action(job_id int, config jsonb) LANGUAGE PLPGSQL AS
    RAISE NOTICE 'Executing job % with config %', job_id, config;

Registering actions

In order to register your action for execution within TimescaleDB's job scheduler, you next need to add_job with the name of your action as well as the schedule on which it is run.

When registered, the action's job_id and config are stored in the TimescaleDB catalog. The config JSONB can be modified with alter_job. job_id and config are passed as arguments when the procedure is executed as background process or when expressly called with run_job.

Register the created job with the automation framework. add_job returns the job_id which can be used to execute the job manually with run_job:

SELECT add_job('user_defined_action','1h', config => '{"hypertable":"metr"}');

To get a list of all currently registered jobs you can query


Found an issue on this page?

Report an issue!


Related Content