Skip to main content

Job Scheduler

Use the Job Scheduler to run an INSERT statement once or on a recurring schedule in a VeloDB Cloud warehouse. Common uses include periodic ingestion from a catalog and SQL transformations between warehouse tables.

A schedule triggers work asynchronously. It does not guarantee that a task starts or finishes at an exact wall-clock time. Cluster capacity, query queues, and the duration of earlier runs affect execution.

Prerequisites and scope​

  • Use a warehouse SQL user with ADMIN_PRIV to create and manage scheduled jobs. The job's SQL must also be valid for its SQL identity.
  • Select an existing database before creating a job, for example, USE reporting;. Give each job a unique name. The inner_ prefix is reserved.
  • Create the source and target tables, and verify the INSERT statement directly before scheduling it.
  • For external sources, configure the catalog, network access, credentials, and driver first. Follow the catalog's deployment requirements. A warehouse connection does not give the cluster access to your source network.
  • This page covers scheduled INSERT jobs. It does not provide a general scheduler for UPDATE, DELETE, arbitrary DDL, or DAG workflows. Use the dedicated loading or orchestration method for those tasks.

Scheduling options​

OptionBehavior
AT 'YYYY-MM-DD HH:MM:SS'Run once at a future timestamp.
AT CURRENT_TIMESTAMPSubmit a one-time task for asynchronous execution as soon as it can be scheduled.
EVERY <quantity> MINUTE, HOUR, DAY, or WEEKRun periodically. The quantity must be positive. Without STARTS, the first scheduled run is one interval after creation.
STARTS <timestamp>Set the first scheduled time for a recurring job. STARTS CURRENT_TIMESTAMP requests an immediate first run.
ENDS <timestamp>Stop producing recurring tasks after the end boundary. Choose an end time later than the start time.

Production recurring schedules use minute, hour, day, or week units. Do not rely on a one-second interval or interpret scheduler timer precision as a completion-time guarantee.

For a full reference, see CREATE JOB.

CREATE JOB <job_name>
ON SCHEDULE {
AT <timestamp>
| EVERY <quantity> { MINUTE | HOUR | DAY | WEEK }
[STARTS <timestamp>]
[ENDS <timestamp>]
}
[COMMENT '<description>']
DO <insert_statement>;

The braces and angle-bracket terms above describe syntax. Replace them with a single valid schedule and SQL statement.

Schedule INSERT statements​

The examples assume that db1.tbl1 and db2.tbl2 already exist and have compatible columns. For the filtered examples, db2.tbl2 must contain create_time. Replace the example dates with future dates for your environment. Use different job names or remove an earlier example before reusing a name.

Repeated INSERT INTO executions append or merge data according to the target table model. A rolling one-day filter can read the same rows more than once. Use an idempotent ingestion design if reruns must not duplicate values.

Example 1: Run every minute​

Schedule a recurring copy between tables
CREATE JOB copy_every_minute
ON SCHEDULE EVERY 1 MINUTE
DO INSERT INTO db1.tbl1 SELECT * FROM db2.tbl2;

This copies the source on every run. It is suitable only when the target model and your data lifecycle handle repeated input.

Example 2: Run once at a future time​

Schedule a one-time copy
CREATE JOB copy_once
ON SCHEDULE AT '2030-01-01 00:00:00'
DO INSERT INTO db1.tbl1 SELECT * FROM db2.tbl2;

Example 3: Start a daily job at a specified time​

Schedule a daily rolling-window load
CREATE JOB copy_daily
ON SCHEDULE EVERY 1 DAY STARTS '2030-01-01 00:00:00'
DO INSERT INTO db1.tbl1
SELECT * FROM db2.tbl2 WHERE create_time >= DAYS_ADD(NOW(), -1);

Example 4: Set a daily job's end time​

Limit a recurring job to a defined time window
CREATE JOB copy_daily_until
ON SCHEDULE EVERY 1 DAY
STARTS '2030-01-01 00:00:00' ENDS '2031-01-01 00:10:00'
DO INSERT INTO db1.tbl1
SELECT * FROM db2.tbl2 WHERE create_time >= DAYS_ADD(NOW(), -1);

Example 5: Submit an asynchronous copy now​

Create a one-time job for immediate scheduling
CREATE JOB copy_async
ON SCHEDULE AT CURRENT_TIMESTAMP
DO INSERT INTO db1.tbl1 SELECT * FROM db2.tbl2;

Job creation returns before the insert task finishes. Inspect the task status to verify the outcome.

Synchronize data from a catalog​

A scheduled job can read an external catalog and write to an internal table. The following example uses MySQL activity records and keeps one aggregate result for each user, date, city, age, and sex key.

1. Prepare the source data​

Run the following in your MySQL source, in an existing user database. The sample dates are historical data values, not schedule times.

CREATE TABLE IF NOT EXISTS user.activity (
`user_id` INT NOT NULL,
`date` DATE NOT NULL,
`city` VARCHAR(20),
`age` SMALLINT,
`sex` TINYINT,
`last_visit_date` DATETIME DEFAULT '1970-01-01 00:00:00',
`cost` BIGINT DEFAULT '0',
`max_dwell_time` INT DEFAULT '0',
`min_dwell_time` INT DEFAULT '99999'
);
INSERT INTO user.activity VALUES
(10000, '2017-10-01', 'BeiJing', 20, 0, '2017-10-01 06:00:00', 20, 10, 10),
(10000, '2017-10-01', 'BeiJing', 20, 0, '2017-10-01 07:00:00', 15, 2, 2),
(10001, '2017-10-01', 'BeiJing', 30, 1, '2017-10-01 17:05:00', 2, 22, 22),
(10002, '2017-10-02', 'ShangHai', 20, 1, '2017-10-02 12:59:00', 200, 5, 5),
(10003, '2017-10-02', 'GuangZhou', 32, 0, '2017-10-02 11:20:00', 30, 11, 11),
(10004, '2017-10-01', 'ShenZhen', 35, 0, '2017-10-01 10:00:00', 100, 3, 3),
(10004, '2017-10-03', 'ShenZhen', 35, 0, '2017-10-03 10:20:00', 11, 6, 6);

2. Create the target table​

In your warehouse, select the database for the target and job:

CREATE DATABASE IF NOT EXISTS reporting;
USE reporting;

CREATE TABLE IF NOT EXISTS user_activity (
`user_id` LARGEINT NOT NULL,
`date` DATE NOT NULL,
`city` VARCHAR(20),
`age` SMALLINT,
`sex` TINYINT,
`last_visit_date` DATETIME,
`cost` BIGINT,
`max_dwell_time` INT,
`min_dwell_time` INT
)
UNIQUE KEY(`user_id`, `date`, `city`, `age`, `sex`)
DISTRIBUTED BY HASH(`user_id`) BUCKETS AUTO;

A Unique Key target replaces the aggregate row for an existing key on subsequent full refreshes. An Aggregate Key target with SUM would add the repeated source totals on each run.

3. Configure and test the catalog​

Create a MySQL JDBC catalog named activity. Use a source account with only the required read privileges. Configure TLS, the reachable source address, and an approved JDBC driver according to that guide. Do not use localhost for a database outside the warehouse.

Before creating a recurring job, test the catalog query and perform one full load:

SELECT * FROM activity.user.activity LIMIT 10;

INSERT INTO reporting.user_activity
SELECT user_id, `date`, city, age, sex,
MAX(last_visit_date), SUM(cost),
MAX(max_dwell_time), MIN(min_dwell_time)
FROM activity.user.activity
GROUP BY user_id, `date`, city, age, sex;

For the two sample records for user 10000, the result has cost = 35, last_visit_date = '2017-10-01 07:00:00', max_dwell_time = 10, and min_dwell_time = 2. These are calculated from the sample values, not measured warehouse output.

4. Schedule the synchronization​

For a one-time full load, use a future off-peak time:

CREATE JOB one_time_load_job
ON SCHEDULE AT '2030-01-01 03:00:00'
DO INSERT INTO reporting.user_activity
SELECT user_id, `date`, city, age, sex,
MAX(last_visit_date), SUM(cost),
MAX(max_dwell_time), MIN(min_dwell_time)
FROM activity.user.activity
GROUP BY user_id, `date`, city, age, sex;

For periodic synchronization, run the same aggregate daily:

CREATE JOB schedule_load
ON SCHEDULE EVERY 1 DAY
DO INSERT INTO reporting.user_activity
SELECT user_id, `date`, city, age, sex,
MAX(last_visit_date), SUM(cost),
MAX(max_dwell_time), MIN(min_dwell_time)
FROM activity.user.activity
GROUP BY user_id, `date`, city, age, sex;

This example rereads the source and replaces rows with matching keys. It does not delete target keys removed from the source or capture every source change as CDC. For large sources, choose a verified incremental strategy or a dedicated ingestion method. Apply a time filter only when it still includes all source rows needed to recompute each affected aggregate.

Inspect and manage jobs​

Use the JOBS and TASKS table functions to inspect definitions, execution status, and errors:

SELECT * FROM JOBS("type" = "insert");
SELECT * FROM TASKS("type" = "insert");

Find the job by name, then inspect its tasks. A job in RUNNING status can schedule tasks. A successful creation statement does not mean its insert task succeeded.

Pause a recurring job before investigating or changing its workload:

PAUSE JOB WHERE jobName = 'schedule_load';

Resume it after resolving the issue:

RESUME JOB WHERE jobName = 'schedule_load';

Remove an unwanted job:

DROP JOB WHERE jobName = 'schedule_load';

See PAUSE JOB, RESUME JOB, and DROP JOB for syntax and cancellation behavior.

Execution behavior and cost​

A job definition produces separate execution tasks. Recurring insert jobs do not start another task while an earlier task from the same job is still running. A scheduled occurrence can therefore be skipped when the previous execution takes too long. Choose an interval longer than the normal execution time, and inspect failures and skipped work.

The scheduler uses internal timers and execution queues. Users do not configure frontend thread pools or service files in VeloDB Cloud. If scheduling remains delayed after you reduce workload pressure, contact VeloDB Cloud support with the job name, task status, error, and time range.

Each run consumes cluster resources and can read external data, incur network charges, and write additional storage. Full scans and short scheduling intervals can substantially increase resource use. Pause or drop demonstration jobs when finished, and remove demonstration tables only after confirming they are no longer needed.

Common errors​

SymptomCause and action
Job creation is deniedUse a warehouse SQL user with ADMIN_PRIV, select a database, and check the SQL statement's object privileges.
A timestamp is rejectedUse a valid future timestamp for a one-time scheduled job and an end boundary later than the start boundary.
The job exists but data is unchangedInspect TASKS for errors, verify that the source query returns rows, and check target table merge behavior.
Some scheduled occurrences do not runCheck whether the preceding task is still running and whether cluster resources or queues delay execution.
Catalog access failsCheck source network access, credentials, TLS, and JDBC driver configuration using the catalog guide.

See also​

Ask AI