Center Timers¶
Timers allow data to be manipulated at consistent time intervals. These intervals can be at specific times, days, dates, or at regular intervals.
CREATE TIMER¶
Overview¶
This command allows you to add script that will be executed on a periodic basis.
timer_name: Name of the timer to create. Each timer's name must be unique within the database.priority: A number, timers with lowest value are executed first. Only considered when two or more timers have the same exact scheduled time.-
schedule: Either:- A positive number defining the period in milliseconds between timer executions
- Empty string ("") to never run timer, useful for timers that should just run at startup, see onStartupScript
-
Crontab style entry declaring the schedule of when the timer should be execute. It has 6 fields separated by spaces, then a time zone:
second minute hour day month weekday timezone. The ranges are second 0-59, minute 0-59, hour 0-23, day 1-31, month 1-12 orJAN-DEC, and weekday 0-6 orSUN-SAT(0 is Sunday). Each field takes*(every value), a number, a range (MON-FRI), a comma-separated list, or*/n(every nth value):
Logging options:
off(default): No logging.on: Logs each statement in the timer's script as it starts and ends (START_QUERYandEND_QUERYlines).verbose: Equivalent of using show_plan=ON in AMIDB. Logs the time that a timer starts and finishes and also each query step.
Example¶
In these examples assume we have the tables A(a boolean) and table B(time utc, cnt int). These timers, when executed, will insert a row into table B with the count of records in A.
DROP TIMER¶
Example¶
This example will drop the timer MyTimer from the database.
Execution Time¶
The actual timer execution period might differ from the one we specified. Consider the following example. There are two timers that are scheduled to run on 5 second periods but take at least 30 seconds to finish. These two commands query the database from MySQL, and are considered deferred statements, where the timer will wait for the last execution to finish before running the next job.
There are several cases:
- If the timer has a specified timeout, the timer will execute again once the timeout has been reached
- For the timer with the Cron schedule, the timer will wait until the next valid time to execute
- In both cases, the timers will either execute every 30 seconds or wait until the previous request finishes executing or has timedout
