CREATE JOB
statement lets you schedule the execution of queries by providing relevant parameters, such as start date, end date, or repetition frequency.
CREATE JOB
Expression | Description |
---|---|
[project_name.]job_name | Name of the job preceded by an optional project name where the job is to be created. If you do not provide the project_name value, then the job is created in the default mindsdb project. |
<statement_1>[; <statement_2>][; ...] | One or more statements separated by ; to be executed by the job. |
[START <date>] | Optional. The date when the job starts its periodical or one-time execution. If not set, it is the current system date. |
[END <date>] | Optional. The date when the job ends its periodical or one-time execution. If it is not set (and the repetition rules are set), then the job repeats forever. |
[EVERY [number] <period>] | Optional. The repetition rules for the job. If not set, the job runs once, not considering the end date value. If the number value is not set, it defaults to 1. |
[IF (<statement_1>[; <statement_2>][; ...])] | Optional. If the last statement returns one or more rows, only then the job will execute. |
<date>
formatsHere are the supported <date>
formats:'%Y-%m-%d %H:%M:%S'
'%Y-%m-%d'
<period>
valuesAnd the supported <period>
values:minute
/ minutes
/ min
hour
/ hours
day
/ days
week
/ weeks
month
/ months
LAST
LAST
keyword that enables you to fetch data inserted/updated after the last time you queried for it. It is a convenient way to select only the newly added data rows when running a job.
Imagine you have the fruit_data
table that contains the following:
SELECT
query with the LAST
keyword for the first time, it’ll fetch all records as below.
(3, 'pear')
into the fruit_data
table. And now this query returns just the newly added row.
home_rentals_model
model and insert predictions into the rentals
table.
join_learn_process
parameter in the USING
clause of the RETRAIN
statement ensures that the retraining process completes before inserting predictions into a table. In general, this parameter is used to prevent several retrain processes from running simultaneously.retrain_model_and_save_predictions
job starts its execution on the current system date and ends on the 1st of April 2023. The job is executed every 2 days.
result_{{START_DATETIME}}
and inserts predictions into it.
{{START_DATETIME}}
variable that is replaced at runtime by the date and time of the current run.You can use the following variables for this purpose:PREVIOUS_START_DATETIME
is replaced by date and time of the previous run of this job.START_DATETIME
is replaced by date and time of the current job run.START_DATE
is replaced by date of the current job run.save_predictions
job starts its execution on the current system date and repeats every 2 hours until it is manually disabled.
home_rentals_model
model scheduled on the 1st of April 2023.
SELECT
statement joins the data table with the model table to get responses for newly posted tweets, thanks to the LAST
keyword. Then, the INSERT INTO
statement writes these responses to the tweets
table of the my_twitter
integration.
config.json
file that you can pass as a parameter when starting your local MindsDB instance:
disable
parameter defines whether the scheduler is active (true
) or not (false
). By default, in the MindsDB Cloud Editor, the scheduler is active.
The check_interval
parameter defines the interval in seconds between consecutive checks of the scheduler table. By default, in the MindsDB Cloud Editor, it is 30 seconds.
You can modify the default configuration in your local MindsDB installation by creating a config.json
file and starting MindsDB with this file as a parameter. You can find detailed instructions here.