Developer_release_1.4.0
Struct app.spec_handlers
Handlers are entry points to Applications.
The Application Developer should define at least one handler. The handlers are triggered either by a D-Bus event or by the Scheduler scheduling system.
Cron-like rules are used to define a schedule. The rules syntax is based on the cron syntax. Unlike the cron rules, the Scheduler's cron-like rules can be made with seconds precision.
The “handlers” table is a key-value table where the key is a schedule definition or D-Bus event name, and the value is a function, which handles the event.
The exception is the schedule definition, which is placed in a special node named cron.
The node is an array of the schedule items. The schedule item is a table containing a handler function and a schedule rule. Schedule rule can be:
- a cron-like expression;
'@start'
which instructs to launch the Application one time on Scheduler start;'@start+N'
which instructs to launch the Application one time after N seconds since Scheduler start.
The handler function should wrap actual handling code and convert schedule item to internal format:
{ cron = '<rule>'; handler = '<wrapped_handler>; }So, the item "
every_minute_action '* * * * *'
" should be
expanded to
{ cron = '* * * * *'; handler = function() -- handling code end; }Example:
return { -- schedule examples cron = { every_minute_action ' * * * * *'; every_fifteen_seconds_action '*/15 * * * * *'; start_action '@start'; after_fifteen_seconds_since_start_action '@start+15'; };-- D-Bus events listeners examples ['com.macnica.BoardInitializationStart'] = board_initialization_start_handler; ['com.example.acme.temperature_checker.TooHotAlert'] = emit_loud_sound_wave; ['com.example.acme.temperature_checker.ExtremelyHotAlert'] = emit_very_loud_sound_wave;
-- web forms handlers (they are also D-Bus events) ['com.example.acme.webscript.api.RegistrationSubmit'] = registration_submit_handler; ['com.example.acme.webscript.api.FeedbackSubmit'] = feedback_submit_handler; }
Сron-like Scheduler Rules Syntax
[second] minute hour day-of-month month day-of-week
second
— (optional) second when the handler will be invoked [0-59];minute
— (required) minute when the handler will be invoked [0-59];hour
— (required) hour when the handler will be invoked [0-23];day-of-month
— (required) day of month when the handler will be invoked [1-28/29/30/31];month
— (required) month when the handler will be invoked [1-12,JAN-DEC];day-of-week
— (required) day of week when the handler will be invoked [0-7/SUN-SAT] (0 and 7 are the Sunday).
Along with the single values, expressions can be used:
- value range, e.g.
1-40,
JAN-MAY;
*
, which means all possible values, e.g.,- for minutes it will be equal to
1-60
- and for day of week it will be
0-6
;
- for minutes it will be equal to
*/n
, which means every nth value from all possible values, e.g.,*/3
,*/45
;
- a comma-separated list of values and/or expressions, e.g.,
1,3,7
,MON,WED,FRI
,*/10,3,4,7-15
.
event
— (required) the Scheduler’s event name; events to support:start
— triggers when the Scheduler starts.
n
— (optional) delay after the event before the handler invocation, in seconds.
@event[+n]
Examples for Сron-like Scheduler Rules
Cron rule | Description |
---|---|
@start @start+0 |
At startup |
@start+75 |
After 75 seconds since startup |
* * * * * */1 * * * * * */1 * * * * */60 * * * * * |
Every minute |
*/2 * * * * |
At every even minute |
1-59/2 * * * * |
At every odd minute |
*/5 * * * * |
Every five minutes |
30 * * * * |
Every hour at minute 30 |
0 */2 * * * |
Every 2nd hour at minute 0 |
0 8-19 * * * |
Every hour from 8 to 19 at minute 0 |
0 0 * * * |
At 00:00 |
1 0 * * SUN |
Every Sunday at 01:00 |
4 30 * * 1-5 |
Every day from Monday to Friday at 04:30 |
7 0 * * 3,6 |
On Wednesday and Saturday at 07:00 |
0 0 1 * * |
On day-of-month 1 at 00:00 |
0 0 1 */2 * |
Every 2nd month on day-of-month 1 at 00:00 |
0 43 9 5 * |
Every 9th of May at 00:43 |