Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docket: add glob contents into eyre cache #260

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 59 additions & 11 deletions desk/app/docket.hoon
Original file line number Diff line number Diff line change
@@ -259,14 +259,16 @@
~| [%took-for-nonexistent-charge desk]
?> |((~(has by charges) desk) ?=([%uninstall ~] wire))
=* cha ~(. ch desk)
=/ pre (~(get by charges) desk)
?+ wire ~|(%bad-charge-wire !!)
::
[%install ~]
?> ?=(%poke-ack -.sign)
?~ p.sign
`state
=. charges (new-chad:cha hung+'Failed install')
((slog leaf+"Failed installing %{(trip desk)}" u.p.sign) `state)
=. charges (new-chad:cha hung+'Failed install')
%. [(new-cache:cha pre) state]
(slog leaf+"Failed installing %{(trip desk)}" u.p.sign)
::
[%uninstall ~]
?> ?=(%poke-ack -.sign)
@@ -285,20 +287,21 @@
?: ?=(%http i.t.t.wire)
hung+'failed to fetch glob via http'
hung+'failed to fetch glob via ames'
((slog leaf+"docket: couldn't {act} thread; will retry" u.p.sign) `state)
%. [(new-cache:cha pre) state]
(slog leaf+"docket: couldn't {act} thread; will retry" u.p.sign)
::
%fact
?+ p.cage.sign `state
%thread-fail
=+ !<([=term =tang] q.cage.sign)
?. |(=(term %cancelled) =(term %http-request-cancelled))
=. charges (new-chad:cha hung+'glob-failed')
:- ~[add-fact:cha]
:- [add-fact:cha (new-cache:cha pre)]
((slog leaf+"docket: thread failed;" leaf+<term> tang) state)
%- (slog leaf+"docket: thread cancelled; retrying" leaf+<term> tang)
=. charges (new-chad:cha %install ~)
:_ state
[add-fact:cha fetch-glob:cha]
[add-fact:cha (weld fetch-glob:cha (new-cache:cha pre))]
::
%thread-done
=+ !<(=glob q.cage.sign)
@@ -314,7 +317,7 @@
=/ have=@uv (hash-glob glob)
?. =(want have)
=. charges (new-chad:cha hung+'glob hash mismatch')
%. `state
%. [(new-cache:cha `charge) state]
=/ url=@t (fall (slaw %t i.t.t.t.wire) '???')
%- slog
:~ leaf+"docket: glob hash mismatch on {<desk>} from {(trip url)}"
@@ -323,7 +326,7 @@
==
=. charges (new-chad:cha glob+glob)
=. by-base (~(put by by-base) base.href.docket.charge desk)
:_(state ~[add-fact:cha])
[[add-fact:cha (new-cache:cha `charge)] state]
==
==
==
@@ -393,14 +396,14 @@
%live
?. ?=(%glob -.href.docket.charge)
=. charges (new-chad:cha %site ~)
:_(state ~[add-fact:cha])
:_(state [add-fact:cha (new-cache:cha `charge)])
:_(state ~[add-fact:cha])
::
?(%held %dead)
=/ glob=(unit glob)
?:(?=(%glob -.chad.charge) `glob.chad.charge ~)
=. charges (new-chad:cha %suspend glob)
:_(state ~[add-fact:cha])
:_(state [add-fact:cha (new-cache:cha `charge)])
==
[[card-1 cards-2] state]
::
@@ -433,7 +436,7 @@
::
?: ?=(%site -.href.docket)
=. charges (new-chad:cha %site ~)
:- ~[add-fact:cha]
:- [add-fact:cha (new-cache:cha pre)]
state
::
=. by-base (~(put by by-base) base.href.docket desk)
@@ -454,7 +457,7 @@
:: if the glob changed, forget the old and fetch the new
::
=. charges (new-chad:cha %install ~)
[[add-fact:cha fetch-glob:cha] state]
[[add-fact:cha (weld fetch-glob:cha (new-cache:cha pre))] state]
[[card-1 cards-2] state]
--
::
@@ -616,6 +619,7 @@
base.href.docket.charge
::
:_ state
%+ weld (new-cache:cha `charge)
::
=/ ours=?
=/ loc location.glob-reference.href.docket.charge
@@ -762,6 +766,50 @@
%+ ~(put by charges) desk
[d chad:(~(gut by charges) desk *charge)]
++ new-chad |=(c=chad (~(jab by charges) desk |=(charge +<(chad c))))
++ new-cache
|= old=(unit charge)
^- (list card)
:: docket tries to serve glob contents from the runtime http server cache.
:: as such, we must keep that cache updated as the glob changes.
::
=; notes=(list note-arvo)
(turn notes arvo:(pass /cache))
%+ weld
:: clear old cache entries, if any
::
?~ old ~
?. ?=(%glob -.chad.u.old) ~
?. ?=(%glob -.href.docket.u.old) ~
=/ base=@t
(cat 3 '/apps/' base.href.docket.u.old)
%+ turn ~(tap by glob.chad.u.old)
|= [=path *]
^- note-arvo
=/ url=@t (rap 3 base (spat (snip path)) '.' (rear path) ~)
[%e %set-response url ~]
:: set new cache entries, if needed
::
=/ new (~(got by charges) desk)
?. ?=(%glob -.chad.new) ~
?. ?=(%glob -.href.docket.new) ~
=/ base=@t
(cat 3 '/apps/' base.href.docket.new)
%+ turn ~(tap by glob.chad.new)
|= [=path =mime]
^- note-arvo
::NOTE +payload-from-glob responds to both /path.ext and /path/ext,
:: and you could argue we should match that behavior here. however,
:: we already don't (cannot) match its "fall back to /index/html"
:: behavior, and the /path.ext case is by far the more common case.
:: so, we simply assume /path.ext intent, ignore /path/ext cases,
:: and reap 95% of the gains that way.
=/ url=@t (rap 3 base (spat (snip path)) '.' (rear path) ~)
=; payload=simple-payload:http
[%e %set-response url ~ & %payload payload]
::NOTE matches +payload-from-glob
:_ `q.mime
:- 200
[content-type+(rsh 3 (crip <p.mime>))]~
++ fetch-glob
^- (list card)
=/ =charge