Skip to content

Commit d249065

Browse files
Merge pull request #229 from permaweb/feat/push-result-depth
feat: optionally include compute results in `push@1.0` output
2 parents e4ee1fb + b72f2f5 commit d249065

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/dev_push.erl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,38 @@ do_push(Base, Assignment, Opts) ->
6565
Slot = hb_ao:get(<<"slot">>, Assignment, Opts),
6666
ID = dev_process:process_id(Base, #{}, Opts),
6767
?event(push, {push_computing_outbox, {process_id, ID}, {slot, Slot}}),
68-
Result = hb_ao:resolve(
68+
{Status, Result} = hb_ao:resolve(
6969
{as, <<"process@1.0">>, Base},
70-
#{ <<"path">> => <<"compute/results/outbox">>, <<"slot">> => Slot },
70+
#{ <<"path">> => <<"compute/results">>, <<"slot">> => Slot },
7171
Opts#{ hashpath => ignore }
7272
),
73+
AdditionalRes =
74+
case IncludeDepth = hb_opts:get(push_include_result, 1, Opts) of
75+
X when X > 0 -> Result;
76+
_ -> #{}
77+
end,
78+
NextOpts =
79+
Opts#{
80+
push_include_result => IncludeDepth - 1
81+
},
7382
?event(push, {push_computed, {process, ID}, {slot, Slot}}),
74-
case Result of
83+
case {Status, hb_ao:get(<<"outbox">>, Result, #{}, Opts)} of
7584
{ok, NoResults} when ?IS_EMPTY_MESSAGE(NoResults) ->
7685
?event(push_short, {push_complete, {process, {string, ID}}, {slot, Slot}}),
77-
{ok, #{ <<"slot">> => Slot, <<"process">> => ID }};
86+
{ok, AdditionalRes#{ <<"slot">> => Slot, <<"process">> => ID }};
7887
{ok, Outbox} ->
7988
Downstream =
8089
maps:map(
8190
fun(Key, MsgToPush = #{ <<"target">> := Target }) ->
8291
case hb_cache:read(Target, Opts) of
8392
{ok, PushBase} ->
84-
push_result_message(PushBase, Slot, Key, MsgToPush, Opts);
93+
push_result_message(
94+
PushBase,
95+
Slot,
96+
Key,
97+
MsgToPush,
98+
NextOpts
99+
);
85100
not_found ->
86101
#{
87102
<<"response">> => <<"error">>,
@@ -101,10 +116,10 @@ do_push(Base, Assignment, Opts) ->
101116
end,
102117
Outbox
103118
),
104-
{ok, Downstream#{
119+
{ok, maps:merge(Downstream, AdditionalRes#{
105120
<<"slot">> => Slot,
106121
<<"process">> => ID
107-
}};
122+
})};
108123
{Err, Error} when Err == error; Err == failure -> {error, Error}
109124
end.
110125

0 commit comments

Comments
 (0)