1
0
mirror of https://github.com/ilyakooo0/urbit.git synced 2024-12-18 04:11:49 +03:00
urbit/pkg/arvo/ted/graph/join.hoon

91 lines
2.2 KiB
Plaintext
Raw Normal View History

2020-09-02 08:18:07 +03:00
/- spider, graph-view, graph=graph-store, *metadata-store, *group
/+ strandio, resource
=>
|%
++ strand strand:spider
2020-09-11 06:08:16 +03:00
++ fail strand-fail:strand
2020-09-02 08:18:07 +03:00
++ poke poke:strandio
++ poke-our poke-our:strandio
2020-09-04 10:51:28 +03:00
::
2020-09-02 08:18:07 +03:00
++ scry-metadata
|= rid=resource
2020-09-02 08:18:07 +03:00
=/ m (strand ,(unit resource))
2020-09-04 10:42:20 +03:00
^- form:m
;< res=(unit resource) bind:m
%+ scry:strandio ,(unit resource)
2020-09-02 08:18:07 +03:00
;: weld
/gx/metadata-store/resource/graph
2020-09-02 08:18:07 +03:00
(en-path:resource rid)
/noun
==
(pure:m res)
::
++ wait-for-group-join
|= rid=resource
=/ m (strand ,~)
^- form:m
=/ pax
(en-path:resource rid)
|- ^- form:m
=* loop $
;< u-group=(unit group) bind:m
(scry:strandio ,(unit group) (weld /gx/group-store/groups (snoc pax %noun)))
?^ u-group
(pure:m ~)
;< ~ bind:m (sleep:strandio `@dr`(div ~s1 2))
loop
::
++ wait-for-md
|= rid=resource
=/ m (strand ,~)
^- form:m
=/ pax
(en-path:resource rid)
|- ^- form:m
=* loop $
;< groups=(set path) bind:m
(scry:strandio ,(set path) /gy/metadata-store/group-indices)
?: (~(has in groups) pax)
(pure:m ~)
;< ~ bind:m (sleep:strandio `@dr`(div ~s1 2))
loop
2020-09-02 08:18:07 +03:00
--
2020-09-04 10:51:28 +03:00
::
2020-09-02 08:18:07 +03:00
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
=+ !<([~ =action:graph-view] arg)
2020-09-02 08:18:07 +03:00
?> ?=(%join -.action)
;< =bowl:spider bind:m get-bowl:strandio
2020-09-11 06:08:16 +03:00
?: =(our.bowl entity.rid.action)
(fail %bad-request ~)
;< group=(unit resource) bind:m (scry-metadata rid.action)
2020-09-02 08:18:07 +03:00
?^ group
:: We have group, graph is managed
2020-09-03 08:07:18 +03:00
;< ~ bind:m
%+ poke-our %graph-pull-hook
2020-09-03 08:07:18 +03:00
pull-hook-action+!>([%add ship.action rid.action])
2020-09-02 08:18:07 +03:00
(pure:m !>(~))
:: Else, add group then join
;< ~ bind:m
2020-09-11 06:08:16 +03:00
%+ (map-err:strandio ,~) |=(* [%forbidden ~])
2020-09-02 08:18:07 +03:00
%+ poke
[ship.action %group-push-hook]
group-update+!>([%add-members rid.action (sy our.bowl ~)])
::
;< ~ bind:m
%+ poke-our %group-pull-hook
pull-hook-action+!>([%add ship.action rid.action])
;< ~ bind:m (wait-for-group-join rid.action)
2020-09-02 08:18:07 +03:00
::
;< ~ bind:m
%+ poke-our %metadata-pull-hook
pull-hook-action+!>([%add ship.action rid.action])::
;< ~ bind:m (wait-for-md rid.action)
::
2020-09-02 08:18:07 +03:00
;< ~ bind:m
2020-09-04 10:42:20 +03:00
%+ poke-our %graph-pull-hook
2020-09-10 13:20:00 +03:00
pull-hook-action+!>([%add ship.action rid.action])
2020-09-02 08:18:07 +03:00
(pure:m !>(~))