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

NameTypeDescription
procREGPROCName of the function or procedure to register as job
schedule_intervalINTERVALInterval between executions of this job. Defaults to 24 hours

Optional arguments

NameTypeDescription
configJSONBJob-specific configuration, passed to the function when it runs
initial_startTIMESTAMPTZTime the job is first run
scheduledBOOLEANSet to FALSE to exclude this job from scheduling. Defaults to TRUE.
check_configREGPROCA 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

ColumnTypeDescription
job_idINTEGERTimescaleDB background job ID

Sample use

Register the user_defined_action procedure to run every hour:

  1. CREATE OR REPLACE PROCEDURE user_defined_action(job_id int, config jsonb) LANGUAGE PLPGSQL AS
  2. $$
  3. BEGIN
  4. RAISE NOTICE 'Executing action % with config %', job_id, config;
  5. END
  6. $$;
  7. SELECT add_job('user_defined_action','1h');