add_job()
Register an action for scheduling by the automation framework. For more information about scheduling, including example actions, see the actions section.
Required arguments
| Name |
Type |
Description |
proc |
REGPROC |
Name of the function or procedure to register as job |
schedule_interval |
INTERVAL |
Interval between executions of this job. Defaults to 24 hours |
Optional arguments
| Name |
Type |
Description |
config |
JSONB |
Job-specific configuration, passed to the function when it runs |
initial_start |
TIMESTAMPTZ |
Time the job is first run |
scheduled |
BOOLEAN |
Set to FALSE to exclude this job from scheduling. Defaults to TRUE. |
check_config |
REGPROC |
A function that takes a single argument, the JSONB config structure. The function is expected to raise an error if the configuration is not valid, and return nothing otherwise. Can be used to validate the configuration when adding a job. Only functions, not procedures, are allowed as values for check_config. |
Returns
| Column |
Type |
Description |
job_id |
INTEGER |
TimescaleDB background job ID |
Sample use
Register the user_defined_action procedure to run every hour:
2. CREATE OR REPLACE PROCEDURE user_defined_action(job_id int, config jsonb) LANGUAGE PLPGSQL AS
4. $$
6. BEGIN
8. RAISE NOTICE 'Executing action % with config %', job_id, config;
10. END
12. $$;
14. SELECT add_job('user_defined_action','1h');