Create and manage jobs
URL: llms-txt#create-and-manage-jobs
Contents:
- Prerequisites
- Create a job
- Test and debug a job
- Alter and delete a job
Jobs in TimescaleDB are custom functions or procedures that run on a schedule that you define. This page explains how to create, test, alter, and delete a job.
To follow the procedure on this page you need to:
- Create a [target Tiger Cloud service][create-service].
This procedure also works for [self-hosted TimescaleDB][enable-timescaledb].
To create a job, create a [function][postgres-createfunction] or [procedure][postgres-createprocedure] that you want your database to execute, then set it up to run on a schedule.
- Define a function or procedure in the language of your choice
Wrap it in a CREATE statement:
For example, to create a function that reindexes a table within your database:
job_id and config are required arguments in the function signature. This returns CREATE FUNCTION to indicate that the function has successfully been created.
- Call the function to validate
The result looks like this:
- Register your job with [
add_job][api-add_job]
Pass the name of your job, the schedule you want it to run on, and the content of your config. For the config value, if you don't need any special configuration parameters, set to NULL. For example, to run the reindex_mytable function every hour:
The call returns a job_id and stores it along with config in the TimescaleDB catalog.
The job runs on the schedule you set. You can also run it manually with [run_job][api-run_job] passing job_id. When the job runs, job_id and config are passed as arguments.
- Validate the job
List all currently registered jobs with [timescaledb_information.jobs][api-timescaledb_information-jobs]:
The result looks like this: