timer_id = alphanum slow_fast = "slow" | "fast" declare_timer_syntax = timer_id "=" (route#|route_name) "," interval "," slow_fast "," ["enable"] enable_disable = "0" | "1"
Declares timer route which will be called in specific interval.
The format is:
declare_timer = declare_timer_syntax
timer_id is timer identifier, route is handler to be called when
timer is triggered, interval is timer interval in milliseconds, slow_fast
determines if handler will be hooked in slow or fast timer queue, fast timer handler returns
as quickly as possible, slow timer handler may spend longer time, see ser/doc/timers.txt documentation. Use enable
to enable timer when ser is starting, otherwise use timer_enable
to start it later.
Example 1. Example declare_timer
... modparam("timer", "declare_timer", "MY_TIMER=MY_TIMER_ROUTE,10,slow,enable"); ...
Enable/disable timer route specified by timer_id
. Because of timer core API the callback
is not disabled immediately but is removed from handler by itself not to decrease performance.
Disabling and enabling in sequence may be tricky.
timer_id references to timer declared by declare_timer
.
Return true ("1") if timer specified by timer_id
is enabled,
otherwise returns false ("0").
Example 5. timer common example
loadmodule "modules/xlog/xlog.so" loadmodule "modules/timer/timer.so" modparam("timer", "declare_timer", "tmr1=ONTIMER,1000"); modparam("timer", "declare_timer", "tmr2=ONTIMER2,2000,slow,enable"); route["print"] { xlog("L_INFO", "fired: %@timer.executed\n"); } route["ONTIMER"] { # do something route("print");} route["ONTIMER2"] { # do something timer_enable("tmr1", 0); route("print"); }
Example 6. Using timer module for testing a functionality
The timer module may be used to test a functionality being developed and not requiring real request.A developer may put tested code in route section which is called once after ser starts.
loadmodule "timer"; loadmodule "xlog"; modparam("timer", "declare_timer", "TIMER_TEST=TEST,100,,enable"); route { xlog("L_E","main route"); } route[TEST] { timer_enable("TIMER_TEST", "0"); xlog("L_E","test start\n"); # add here tested functionality xlog("L_E","test end\n"); }