Creating a task

You can create a Scheduler task to perform a specific action at specific times.

Before you begin

You must be connected to the sysadmin database as user informix or another authorized user.

About this task

To create a task, use an INSERT statement to add a row into the ph_task table:

Procedure

  1. Include values for the following columns:
    1. tk_name: Give the task a unique name.
    2. tk_type: Change the job type to TASK or STARTUP TASK.
    3. tk_description: Add a description of the action the task performs.
    4. tk_execute: Add the action that the task performs.
      The action can be a user-defined function, a single SQL statement, or a multiple-statement prepared object that was created using the PREPARE SQL to enable the assembly of one or more SQL statements at runtime.
      The length of the command is limited to 2048 bytes.
  2. Optional: Change the default values for the following columns:
    • tk_start_time: The default start time is 8:00:00. For a startup task, set the start time to NULL.
    • tk_stop_time: The default stop time is 19:00:00. For a startup task, set the stop time to NULL.
    • tk_frequency: The default frequency once a day. For a startup task, set the frequency to NULL.
    • tk_group: The default group is MISC.
    • tk_monday through tk_sunday: The default is to run every day.

Results

The task runs at the specified start time and subsequently at the time calculated from the frequency.

Example

The following task uses the SQL administration API to take a checkpoint every two minutes between the hours of 8:00 A.M. and 7:00 P.M. on Mondays, Wednesdays, and Fridays.

INSERT INTO ph_task
( tk_name,
tk_description,
tk_type,
tk_group,
tk_execute,
tk_start_time,
tk_stop_time,
tk_frequency,
tk_Monday,
tk_Tuesday,
tk_Wednesday,
tk_Thursday,
tk_Friday,
tk_Saturday,
tk_Sunday)
VALUES
( "Example Checkpoint",
"Example to do a checkpoint every 2 minutes.",
"TASK",
"EXAMPLES",
"EXECUTE FUNCTION admin('checkpoint')",
DATETIME(08:00:00) HOUR TO SECOND,
DATETIME(19:00:00) HOUR TO SECOND,
INTERVAL ( 2 ) MINUTE TO MINUTE,
't',
'f',
't',
'f',
't',
'f',
'f');
The following example shows the code for a task that runs once a day at 2:00 A.M. to ensure that the command_history table contains only recent data. In this example, the definition of recent data is stored in a Command History Interval column in the ph_threshold table.
INSERT INTO ph_task
(
tk_name,
tk_group,
tk_description,
tk_type,
tk_execute,
tk_start_time,
tk_frequency
)
VALUES
(
"mon_command_history",
"TABLES",
"Monitor how much data is kept in the command history table",
"TASK",
"delete from command_history where cmd_exec_time < (
        select current - value::INTERVAL DAY to SECOND
        from ph_threshold
        where name = 'COMMAND HISTORY INTERVAL' ) ",
"2:00:00",
"1 0:00:00"
);