urbit/pkg/arvo/app/glob.hoon

293 lines
8.3 KiB
Plaintext
Raw Normal View History

:: glob [landscape]:
::
:: prompts content delivery and Gall state storage for Landscape JS blob
2020-09-25 12:31:17 +03:00
::
2021-05-19 01:12:39 +03:00
/- glob, *resource
/+ default-agent, verb, dbug
|%
++ landscape-hash 0v1.0psg8.dk5ii.hse9j.daslg.h83mu
++ btc-wallet-hash 0v6.h33vk.c3n1c.4gpkn.cci4c.pnh4r
+$ state-0 [%0 hash=@uv glob=(unit (each glob:glob tid=@ta))]
2021-05-19 01:12:39 +03:00
+$ state-1 [%1 =globs:glob]
+$ all-states
$% state-0
2021-05-19 01:12:39 +03:00
state-1
==
+$ card card:agent:gall
--
|%
2020-07-18 02:58:28 +03:00
++ wait-timeout
|= [=path now=@da]
^- card
2020-07-18 02:58:28 +03:00
[%pass [%timer path] %arvo %b %wait (add now ~m30)]
::
++ wait-start
2021-05-19 01:12:39 +03:00
|= [now=@da =path]
2020-07-18 02:58:28 +03:00
^- card
2021-05-19 01:12:39 +03:00
[%pass [%start path] %arvo %b %wait now]
::
++ poke-file-server
2021-05-19 01:12:39 +03:00
|= [our=@p hash=@uv =cage]
^- card
[%pass /serving/(scot %uv hash) %agent [our %file-server] %poke cage]
::
++ poke-spider
|= [=path our=@p =cage]
^- card
[%pass [%running path] %agent [our %spider] %poke cage]
::
++ watch-spider
|= [=path our=@p =sub=path]
^- card
[%pass [%running path] %agent [our %spider] %watch sub-path]
::
++ leave-spider
|= [=path our=@p]
^- card
[%pass [%running path] %agent [our %spider] %leave ~]
--
2021-05-19 01:12:39 +03:00
=| state=state-1
=. globs.state
(~(put by globs.state) /'~landscape'/js/bundle landscape-hash ~)
=. globs.state
2021-05-27 04:28:55 +03:00
(~(put by globs.state) /'~btc'/js/bundle btc-wallet-hash ~)
2021-05-19 01:12:39 +03:00
::
^- agent:gall
%+ verb |
%- agent:dbug
^- agent:gall
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
++ on-init
^- (quip card _this)
2020-07-18 02:58:28 +03:00
:: delay through timer to make sure %spider has started
2021-05-19 01:12:39 +03:00
:_ this
%+ turn ~(tap by ~(key by globs.state))
|=(=path (wait-start now.bowl path))
::
++ on-save !>(state)
++ on-load
|= old-state=vase
^- (quip card _this)
=+ !<(old=all-states old-state)
2021-05-19 01:12:39 +03:00
=| cards=(list card)
=/ upgrading=? %.n
|-
?- -.old
%1
=/ [cards-1=(list card) =globs:glob]
%- ~(rep by globs.old)
|= $: [=serve=path =glob-details:glob]
cards=(list card)
globs=_globs.state
==
^- [(list card) globs:glob]
=/ new-glob-details (~(get by globs) serve-path)
?~ new-glob-details
[cards globs]
?~ glob.glob-details
:_ globs
[(wait-start now.bowl serve-path) cards]
?: ?=(%& -.u.glob.glob-details)
?: =(hash.u.new-glob-details hash.glob-details)
[cards (~(put by globs) serve-path glob-details)]
:_ globs
[(wait-start now.bowl serve-path) cards]
?: upgrading
:_ globs
[(wait-start now.bowl serve-path) cards]
=/ args [tid.p.u.glob.glob-details &]
=/ spider-wire [(scot %uv hash.glob-details) serve-path]
:_ globs
:* (leave-spider spider-wire our.bowl)
(poke-spider spider-wire our.bowl %spider-stop !>(args))
(wait-start now.bowl serve-path)
cards
==
:- (weld cards cards-1)
this(globs.state globs)
::
%0
=/ globs
2021-05-27 21:52:56 +03:00
(~(put by globs.state) /'~landscape'/js/bundle [hash.old glob.old])
2021-05-19 01:12:39 +03:00
%= $
old [%1 globs]
::
cards
?~ glob.old ~
?: =(%& -.u.glob.old) ~
?> ?=(%| -.u.glob.old)
=/ args [tid.p.u.glob.old &]
:~ (leave-spider /(scot %uv hash.old) our.bowl)
(poke-spider /(scot %uv hash.old) our.bowl %spider-stop !>(args))
==
::
upgrading %.y
==
2021-05-19 01:12:39 +03:00
==
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
2020-07-18 02:58:28 +03:00
?+ mark (on-poke:def mark vase)
%glob-make
2021-05-19 01:12:39 +03:00
=+ !<(dir=path vase)
2020-07-18 02:58:28 +03:00
:_ this
=/ home=path /(scot %p our.bowl)/home/(scot %da now.bowl)
2021-05-19 01:12:39 +03:00
=+ .^(paths=(list path) %ct (weld home dir))
=+ .^(=js=tube:clay %cc (weld home /js/mime))
=+ .^(=map=tube:clay %cc (weld home /map/mime))
=/ =glob:glob
%- ~(gas by *glob:glob)
2021-05-19 01:12:39 +03:00
%+ turn paths
|= pax=path
^- [path mime]
=+ .^(file=@t %cx (weld home pax))
=/ mar (snag 0 (flop pax))
:- (slag (lent dir) pax)
?+ mar ~|(unsupported-glob-type+mar !!)
%js !<(mime (js-tube !>(file)))
%map !<(mime (map-tube !>(file)))
==
2020-07-18 02:58:28 +03:00
=/ =path /(cat 3 'glob-' (scot %uv (sham glob)))/glob
2021-05-19 01:12:39 +03:00
~& globbed+`(set ^path)`~(key by glob)
2020-07-18 02:58:28 +03:00
[%pass /make %agent [our.bowl %hood] %poke %drum-put !>([path (jam glob)])]~
::
%noun
2021-05-19 01:12:39 +03:00
?: =(%kick -.q.vase)
=+ !<([%kick =path] vase)
=/ glob-details (~(get by globs.state) path)
?~ glob-details
~& no-such-glob+path
`this
=/ new-state
state(globs (~(put by globs.state) path *@uv glob.u.glob-details))
(on-load !>(new-state))
2020-07-18 02:58:28 +03:00
(on-poke:def mark vase)
==
::
++ on-watch on-watch:def
++ on-leave on-leave:def
2021-05-19 02:28:38 +03:00
::
++ on-peek
|= =path
^- (unit (unit cage))
?+ path (on-peek:def path)
2021-05-27 04:28:55 +03:00
[%x %btc-wallet ~] ``noun+!>(btc-wallet-hash)
2021-05-19 02:28:38 +03:00
==
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
?: ?=([%serving @ ~] wire)
(on-agent:def wire sign)
2020-07-18 02:58:28 +03:00
?: ?=([%make ~] wire)
(on-agent:def wire sign)
2021-05-19 01:12:39 +03:00
?. ?=([%running @ *] wire)
%- (slog leaf+"glob: strange on-agent! {<wire -.sign>}" ~)
(on-agent:def wire sign)
2021-05-19 01:12:39 +03:00
::
=/ produced-hash (slav %uv i.t.wire)
=* serve-path t.t.wire
=/ glob-details (~(get by globs.state) serve-path)
?~ glob-details
[~ this]
?. =(hash.u.glob-details produced-hash)
[~ this]
?- -.sign
%poke-ack
?~ p.sign
[~ this]
%- (slog leaf+"glob: couldn't start thread; will retry" u.p.sign)
2021-05-19 01:12:39 +03:00
:_ this(globs.state (~(put by globs.state) serve-path produced-hash ~))
[(leave-spider t.wire our.bowl)]~
::
%watch-ack
?~ p.sign
[~ this]
%- (slog leaf+"glob: couldn't listen to thread; will retry" u.p.sign)
2021-05-19 01:12:39 +03:00
[~ this(globs.state (~(put by globs.state) serve-path produced-hash ~))]
::
%kick
2021-05-19 01:12:39 +03:00
?. ?=([~ %| *] glob.u.glob-details)
`this
[~ this(globs.state (~(put by globs.state) serve-path produced-hash ~))]
::
%fact
?+ p.cage.sign (on-agent:def wire sign)
%thread-fail
=+ !<([=term =tang] q.cage.sign)
%- (slog leaf+"glob: thread failed; will retry" leaf+<term> tang)
2021-05-19 01:12:39 +03:00
:- ~
this(globs.state (~(put by globs.state) serve-path produced-hash ~))
::
%thread-done
=+ !<(=glob:glob q.cage.sign)
2021-05-19 01:12:39 +03:00
?. =(hash.u.glob-details (sham glob))
%: mean
leaf+"glob: hash doesn't match!"
2021-05-19 01:12:39 +03:00
>expected=hash.u.glob-details<
>got=(sham glob)<
~
==
2021-05-19 01:12:39 +03:00
=. globs.state
(~(put by globs.state) serve-path produced-hash `[%& glob])
:_ this :_ ~
%: poke-file-server
our.bowl
produced-hash
%file-server-action
!>([%serve-glob serve-path glob %&])
==
==
==
::
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card _this)
2021-05-19 01:12:39 +03:00
?: ?=([%start *] wire)
=* serve-path t.wire
=/ glob-details (~(get by globs.state) serve-path)
?~ glob-details
[~ this]
=/ new-tid=@ta (cat 3 'glob--' (scot %uv (sham eny.bowl serve-path)))
=/ args [~ `new-tid %glob !>([~ hash.u.glob-details])]
=/ action=cage [%file-server-action !>([%unserve-dir serve-path])]
=/ spider-wire [(scot %uv hash.u.glob-details) serve-path]
=. globs.state
(~(put by globs.state) serve-path hash.u.glob-details `[%| new-tid])
:_ this
:~ (poke-file-server our.bowl hash.u.glob-details action)
(wait-timeout [new-tid serve-path] now.bowl)
(watch-spider spider-wire our.bowl /thread-result/[new-tid])
(poke-spider spider-wire our.bowl %spider-start !>(args))
2020-07-18 02:58:28 +03:00
==
2021-05-19 01:12:39 +03:00
::
?. ?=([%timer @ *] wire)
%- (slog leaf+"glob: strange on-arvo wire: {<wire [- +<]:sign-arvo>}" ~)
`this
?. ?=(%wake +<.sign-arvo)
%- (slog leaf+"glob: strange on-arvo sign: {<wire [- +<]:sign-arvo>}" ~)
`this
2021-05-19 01:12:39 +03:00
=* serve-path t.wire
=/ glob-details (~(get by globs.state) serve-path)
?~ glob-details
`this
?: ?=([~ %& *] glob.u.glob-details)
`this
2021-05-19 01:12:39 +03:00
?. ?| ?=(~ glob.u.glob-details)
=(i.t.wire tid.p.u.glob.u.glob-details)
==
`this
?^ error.sign-arvo
%- (slog leaf+"glob: timer handling failed; will retry" ~)
2020-07-18 02:58:28 +03:00
[[(wait-timeout t.wire now.bowl)]~ this]
%- (slog leaf+"glob: timed out; retrying" ~)
2021-05-19 01:12:39 +03:00
=/ new-details u.glob-details(hash *@uv)
=/ new-state state(globs (~(put by globs.state) serve-path new-details))
(on-load !>(new-state))
::
++ on-fail on-fail:def
--