GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.voltdb.com — CREATE TASK Using VoltDBCREATE TASKCREATE TASK — Schedules a procedure to run periodically. SynopsisCREATE TASK task-name CREATE TASK task-name time-interval: integer {MILLISECONDS | SECONDS | MINUTES | HOURS | DAYS} DescriptionThe CREATE TASK statement schedules a stored procedure to run iteratively on a set schedule. In its simplest form, the CREATE TASK statement schedules a specified stored procedure to be run at a regular interval. The PROCEDURE clause specifies the stored procedure and any arguments it requires. The ON SCHEDULE clause specifies when the procedure will be run. You can schedule a procedure to run on three types of schedule:
The difference between DELAY and EVERY is how the interval is measured. For example, if you specify EVERY 5 SECONDS, the stored procedure runs every 5 seconds, no matter how long it takes to execute (assuming it does not take more than 5 seconds). If, on the other hand, you specify DELAY 5 SECONDS, each run starts 5 seconds after the previous run completes. In other words, EVERY results in invocations at a regular interval no matter how long they take, while DELAY results in a regular interval between when one run ends and the next begins. For DELAY and EVERY you specify the interval as a positive integer and a time unit, where the supported time units are milliseconds, seconds, minutes, hours, and days. For EVERY, if the previous run takes longer than the interval to run, the schedule is reset at the end of the previous run. So, for example, if the schedule specifies EVERY 2 SECONDS but the procedure takes 2.5 seconds to run, the next scheduled interval will already be past when the previous run ends. In this case, the next invocation of the task is reset to 2 seconds after the previous run ends. The CRON option requires a standard cron schedule, which consists of six values separated by spaces. Cron schedules
set specific times of day, week, or month, rather than an interval. The six values of the cron string represent seconds,
minutes, hours, day of the month, month, and day of the week. Asterisks indicate all possible values. For example, the cron
specification You can also specify details about how the procedure is run:
Finally, you can use the ENABLE and DISABLE keywords to specify whether the task is enabled or not. (The task is enabled by default.) If the task is disabled, the procedure is not invoked. If the task is enabled, the procedure is invoked according to the schedule until the database shuts down or the task is disabled by an ALTER TASK statement or an error while ON ERROR STOP is active. Creating Custom TasksIf the standard schedules do not meet your needs — you want to change the interval between runs, modify the arguments to the procedure , or the procedure itself — you can define a custom task using Java classes that implement one of three special interfaces:
Before declaring a custom task, you must load the specified Java class, the same way you load Java classes before declaring a user-defined stored procedure, by packaging it in a JAR file and using the LOAD CLASSES directive in sqlcmd. It is also important to note that the classes used for custom tasks are not stored procedures and do not run in the normal transactional path for VoltDB transactions. The custom task classes run in a separate thread to identify the characteristics of the next task invocation before the specified stored procedure is run. For all three task interfaces, the task management infrastructure provides the results from the previous run as input to the callback method, which can then use that information to determine how to modify the next instantiation of the task's procedure, parameters, or run interval. Many of the CREATE TASK statement's clauses — ON ERROR, AS USER, and ENABLE|DISABLE — operate exactly the same for both custom tasks and the simple case of scheduling a single stored procedure. The two exceptions are the WITH and RUN ON clauses. For custom tasks that alter the procedure and procedure parameters, the arguments in the WITH clause are passed to the
custom task's The RUN ON clause for a custom task has one additional option beyond just DATABASE and PARTITIONS. Custom tasks can also be RUN ON HOSTS, which means one instance of the task is run on each server in the cluster. ExamplesThe following example declares a procedure to reset the DailyStats view, and a task scheduled as a cron event at midnight every night to run the procedure. CREATE PROCEDURE ResetDailyStats AS DELETE FROM DailyStats; CREATE TASK nightly ON SCHEDULE CRON 0 0 0 * * * PROCEDURE ResetDailyStats RUN ON DATABASE; The next example creates a custom task that dynamically changes the interval between invocations of the stored procedure. The example first loads the JAR file containing a custom task class that implements the IntervalGenerator interface and then declares the task using PROCEDURE FROM CLASS clause. sqlcmd 1> LOAD CLASSES mytasks.jar; 2> CREATE TASK DailyNoHolidays ON SCHEDULE FROM CLASS mytasks.NoHolidays PROCEDURE ResetDailyStats RUN ON DATABASE; |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |