-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.picolabs.wovyn.schedule_test.krl
60 lines (48 loc) · 1.31 KB
/
io.picolabs.wovyn.schedule_test.krl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ruleset io.picolabs.wovyn.schedule_test {
meta {
name "schedule_test"
description <<
Testing if schedules work
>>
author "PJW"
use module io.picolabs.wrangler alias wrangler
use module io.picolabs.subscription alias subs
shares gossip_schedule, gossip_period
// provides
}
global {
gossip_schedule = function(){schedule:list()};
gossip_period = function(){ent:gossip_period};
}
rule gossip {
select when sensor gossip
always {
schedule sensor event "gossip" at time:add(time:now(), {"seconds": gossip_period()}).klog("Future: ") setting(id);
ent:current_gossip_schedule := id.klog("Gossip schedule ID: ");
}
}
rule stop_gossiping {
select when sensor no_gossip
schedule:remove(ent:current_gossip_schedule);
}
rule clear_schedule {
select when sensor clear_schedule
foreach gossip_schedule() setting(id)
schedule:remove(id);
}
rule set_gossip_period {
select when sensor gossip_period
always {
ent:gossip_period := event:attr("seconds").defaultsTo(20)
}
}
rule inialize_ruleset {
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
pre {
}
if true then send_directive(<<Initializing #{meta:rid}>>)
fired {
ent:gossip_period := 20;
}
}
}