@@ -11,10 +11,16 @@ $:
1111+$ state-0
1212$:
1313 search-subscriptions=(map query search-state)
14+ peers=(set @p)
15+ alive-peers=(set @p)
1416==
1517+$ poke
1618 $%
17− [%search query=tape]
19+ :: [%search query=tape]
20+ [%liveness-check ~]
21+ [%add-peers (set @p)]
22+ :: [%ping ~]
23+ :: [%pong ~]
1824 ==
1925++ rank-results
2026 |= search-results=(map term (unit (list search-result)))
@@ -39,6 +45,7 @@ $:
3945 ^- task:iris
4046 [%request [%'GET' (crip (url.engine (trip query))) ~ ~] *outbound-config:iris]
4147 [%pass ~[%search-result query engine-name] %arvo %i req]
48+ ++ liveness-interval ~s30
4249--
4350
4451=/ state *state-0
@@ -62,7 +69,6 @@ $:
6269 search-results.search-state
6370=* sink-for-query
6471 |= =query
65− ~& (~(get by search-subscriptions.state) query)
6672 [(current-engines query) (search-results query)]
6773=* sink
6874 |= =query
@@ -72,7 +78,9 @@ $:
7278%- agent:dbug
7379|_ =bowl:gall
7480+* this .
75−++ on-init `..on-init
81+ liveness-behn-card [%pass /check-liveness %arvo %b %wait (add now.bowl liveness-interval)]
82+++ on-init
83+ [~[liveness-behn-card] this]
7684++ on-save !>(state)
7785++ on-load
7886 |= =vase
@@ -84,7 +92,18 @@ $:
8492++ on-poke
8593 |= =cage
8694 ^- (quip card:agent:gall _this)
87− `this
95+ ?> ?=(%noun -.cage)
96+ =/ poke !<(poke +.cage)
97+ ?- -.poke
98+ %liveness-check
99+ [~[liveness-behn-card] this]
100+ %add-peers
101+ `this(peers.state (~(uni in peers.state) +.poke))
102+ ==
103+
104+ :: %ping
105+
106+
88107
89108++ on-watch
90109 |= =path
@@ -104,13 +123,22 @@ $:
104123 =. search-subscriptions.state
105124 (~(put by search-subscriptions.state) query subscription)
106125 [~[flush:(sink query)] this]
126+ [%ping ~]
127+ ~& path
128+ :-
129+ :~
130+ [%give %fact ~ %noun !>(%pong)]
131+ [%give %kick ~ ~]
132+ ==
133+ this
134+
107135 ==
108136
109137:: This was not tested because it requires waiting 12 hours.
110138++ on-leave
111139 |= =path
112− ?+ path !!
113− [%search query ~]
140+ ?+ path `this
141+ [%search query ~]
114142 =/ query +<.path
115143 ~& path
116144 =/ search-state (~(got by search-subscriptions.state) query)
@@ -125,7 +153,17 @@ $:
125153++ on-peek
126154 |= path
127155 ~
128−++ on-agent |=([wire sign:agent:gall] !!)
156+++ on-agent
157+ |= [=wire =sign:agent:gall]
158+ ?+ wire `this
159+ [%alive ~]
160+ ?+ -.sign `this
161+ %fact
162+ ~& "{<src.bowl>} is alive"
163+ =. alive-peers.state (~(put in alive-peers.state) src.bowl)
164+ `this
165+ ==
166+ ==
129167++ on-arvo
130168 |= [=wire =sign-arvo]
131169 ^- (quip card:agent:gall _this)
@@ -149,6 +187,18 @@ $:
149187 =^ card sink (sync:sink (sink-for-query query))
150188 ~& (current-engines query)
151189 [~[card] this]
190+ [%check-liveness ~]
191+ =/ checks
192+ %+ turn ~(tap in peers.state)
193+ |= peer=@p
194+ [%pass /alive %agent [peer %seax] %watch /ping]
195+ =. peers.state alive-peers.state
196+ =. alive-peers.state *(set @p)
197+ =/ timer
198+ liveness-behn-card
199+ :-
200+ [timer checks]
201+ this
152202 ==
153203++ on-fail
154204 |= [term =tang]