%% plans/ra_kernel.erl — RA/TA persistent-kernel SPIKE. %% A minimal long-lived next/ kernel: starts flow_store + registers the publish-digest flow, then %% blocks in http:listen — keeping the er-scheduler (and flow_store's gen_server) alive across %% requests. Two routes drive flow_store over HTTP: GET /start (start a newsletter flow → suspend) %% and GET /resume (resume instance 1 → done). If /resume completes in a SEPARATE request from %% /start, the gen_server persisted across requests — the persistent-kernel prerequisite for %% RA-live + TA-live holds. -module(ra_kernel). -export([start/1]). start(Port) -> flow_store:start_link(), FF = fun (_) -> [f1, f2, f3] end, flow_store:register_flow(bd, blog_publish_digest:build([{fetch_followers, FF}])), http:listen(Port, fun (Req) -> route(Req) end). route(Req) -> [{status, 200}, {headers, []}, {body, respond(field(path, Req))}]. %% /start (bytes 47,115,116,97,114,116) respond(<<47,115,116,97,114,116>>) -> Env = [{activity, [{type, create}, {actor, alice}, {id, <<110,49>>}, {object, [{type, article}, {category, newsletter}]}]}, {actor, alice}], case flow_store:start(bd, Env) of {ok, _Id, {flow_suspended, _}} -> <<"start:suspended">>; {ok, _Id, {flow_done, _}} -> <<"start:done">>; _ -> <<"start:other">> end; %% /resume (bytes 47,114,101,115,117,109,101) respond(<<47,114,101,115,117,109,101>>) -> case flow_store:resume(1, morning_ts) of {ok, {flow_done, _}} -> <<"resume:done">>; {flow_done, _} -> <<"resume:done">>; _ -> <<"resume:other">> end; respond(_) -> <<"path:unknown">>. field(K, [{K, V} | _]) -> V; field(K, [_ | Rest]) -> field(K, Rest); field(_, []) -> nil.