eth-watcher: keep timers going

This commit is contained in:
Philip Monk 2019-11-30 19:38:43 -08:00
parent f30daf5af2
commit 0eaad536a0
No known key found for this signature in database
GPG Key ID: B66E1F02604E44EC
6 changed files with 68 additions and 30 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:98085813b4b4bd7d5a1700cce396184dbc5931d21993a0d27c6dee6d2d36d413
size 10054377
oid sha256:fe89a6c695902617b4f87dbd3f8ad024cfedf6e3830f44e09f9022d21678e948
size 10073299

View File

@ -8,7 +8,7 @@
=> |%
+$ card card:agent:gall
+$ app-state
$: %1
$: %2
dogs=(map path watchdog)
==
::
@ -74,7 +74,8 @@
|^
=+ !<(old-state=app-states old)
=? old-state ?=(%0 -.old-state)
^- app-state
%- (slog leaf+"upgrading eth-watcher from %0" ~)
^- app-state-1
%= old-state
- %1
dogs
@ -84,10 +85,25 @@
-> [~m5 ->.dog]
==
==
`this(state ?>(?=(%1 -.old-state) old-state))
::
=^ cards-1=(list card) old-state
%- (slog leaf+"upgrading eth-watcher from %1" ~)
?. ?=(%1 -.old-state)
`old-state
:_ old-state(- %2)
%+ turn ~(tap by dogs.old-state)
|= [=path dog=watchdog]
(wait-shortcut path now.bowl)
::
`this(state ?>(?=(%2 -.old-state) old-state))
::
+$ app-states
$%(app-state-0 app-state)
$%(app-state-0 app-state-1 app-state)
::
+$ app-state-1
$: %1
dogs=(map path watchdog)
==
::
+$ app-state-0
$: %0
@ -185,11 +201,16 @@
++ on-peek
|= =path
^- (unit (unit cage))
?. ?=([%x %block ^] path) ~
?. (~(has by dogs.state) t.t.path) ~
:+ ~ ~
:- %atom
!>(number:(~(got by dogs.state) t.t.path))
?+ path ~
[%x %block ^]
?. (~(has by dogs.state) t.t.path) ~
:+ ~ ~
:- %atom
!>(number:(~(got by dogs.state) t.t.path))
::
[%x %dogs ~]
``noun+!>(~(key by dogs.state))
==
::
++ on-agent
|= [=wire =sign:agent:gall]
@ -305,7 +326,7 @@
^- (quip card agent:gall)
?+ +<.sign-arvo ~|([%strange-sign-arvo -.sign-arvo] !!)
%wake
?. ?=([%timer *] wire) [~ this]
?. ?=([%timer *] wire) ~& weird-wire=wire [~ this]
=* path t.wire
?. (~(has by dogs.state) path)
[~ this]
@ -315,14 +336,16 @@
:: failed, try again. maybe should tell user if fails more than
:: 5 times.
::
%- (slog leaf+"eth-watcher failed; will retry" ~)
[[(wait path now.bowl refresh-rate.dog)]~ this]
:: start a new thread that checks for updates
::
=- [cards this(dogs.state (~(put by dogs.state) path dog))]
^- [cards=(list card) dog=watchdog]
?^ running.dog
=^ cards-1=(list card) dog
:: if still running, kill it and restart
::
?~ running.dog
`dog
::
%- (slog leaf+"eth-watcher still running; will restart" ~)
=/ =cage [%spider-stop !>([u.running.dog |])]
:_ dog(running ~)
@ -330,15 +353,19 @@
(leave-spider path our.bowl)
==
::
=/ new-tid=@ta
(cat 3 'eth-watcher--' (scot %uv eny.bowl))
:_ dog(running `new-tid)
=/ args
:^ ~ `new-tid %eth-watcher
!>(`watchpup`[- number pending-logs blocks]:dog)
:~ (watch-spider path our.bowl /thread-result/[new-tid])
(poke-spider path our.bowl %spider-start !>(args))
==
=^ cards-2=(list card) dog
=/ new-tid=@ta
(cat 3 'eth-watcher--' (scot %uv eny.bowl))
:_ dog(running `new-tid)
=/ args
:^ ~ `new-tid %eth-watcher
!>(`watchpup`[- number pending-logs blocks]:dog)
:~ (watch-spider path our.bowl /thread-result/[new-tid])
(poke-spider path our.bowl %spider-start !>(args))
==
::
:- [(wait path now.bowl refresh-rate.dog) (weld cards-1 cards-2)]
this(dogs.state (~(put by dogs.state) path dog))
==
::
++ on-fail on-fail:def

View File

@ -319,7 +319,9 @@
?: (~(has by starting.state) yarn)
(thread-fail-not-running tid %stopped-before-started ~)
~& [%thread-not-started yarn]
`state
?: nice
(thread-done yarn *vase)
(thread-fail yarn %cancelled ~)
::
++ take-input
|= [=yarn input=(unit input:strand)]

View File

@ -92,16 +92,24 @@
++ latest-block
(add launch:contracts:azimuth (dec (lent logs.state)))
::
++ get-single-req
|= req=@t
=/ batch
((ar:dejs:format same) (need (de-json:html req)))
?> ?=([* ~] batch)
i.batch
::
++ get-id
|= req=@t
=, dejs:format
%. (need (de-json:html req))
%. (get-single-req req)
(ot id+so ~)
::
++ get-method
|= req=@t
=, dejs:format
%. (need (de-json:html req))
~| req=req
%. (get-single-req req)
(ot method+so ~)
::
++ get-param-obj
@ -109,7 +117,7 @@
=, dejs:format
%- hex-to-num:ethereum
=/ array
%. (need (de-json:html req))
%. (get-single-req req)
(ot params+(ar (ot param^so ~)) ~)
?> ?=([* ~] array)
i.array
@ -119,7 +127,7 @@
^- (unit @ud)
=, dejs-soft:format
=/ array
%. (need (de-json:html req))
%. (get-single-req req)
(ot params+(ar (ot param^so ~)) ~)
?~ array
~
@ -132,7 +140,7 @@
|= req=@t
=, dejs:format
=/ id
%. (need (de-json:html req))
%. (get-single-req req)
(ot params+(at so bo ~) ~)
-.id
::
@ -142,6 +150,7 @@
=/ resp
%- crip
%- en-json:html
:- %a :_ ~
%- pairs
:~ id+s+(get-id req)
jsonrpc+s+'2.0'

Binary file not shown.

Binary file not shown.