This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-22
Channels
- # ai (1)
- # announcements (4)
- # babashka (23)
- # beginners (27)
- # biff (17)
- # calva (5)
- # clerk (6)
- # clj-commons (27)
- # clj-kondo (35)
- # clojars (12)
- # clojure (27)
- # clojure-denver (3)
- # clojure-europe (71)
- # clojure-norway (7)
- # clojure-spec (5)
- # clojure-uk (2)
- # clojurescript (45)
- # data-science (9)
- # datomic (4)
- # dev-tooling (2)
- # devcards (1)
- # hoplon (2)
- # hyperfiddle (36)
- # introduce-yourself (3)
- # malli (11)
- # missionary (2)
- # off-topic (63)
- # polylith (5)
- # rdf (2)
- # reagent (12)
- # schema (1)
- # shadow-cljs (11)
- # sql (6)
- # tools-deps (23)
- # xtdb (6)
Is there an example of a Babashka Pod that streams output back to the client? 🧵
Maybe I have to write to a temporary file? Like in https://github.com/babashka/pod-babashka-aws/blob/main/src/pod/babashka/aws.clj#L70-L71
Maybe something like mentioned here https://github.com/babashka/pods/issues/1
Maybe https://github.com/babashka/pod-babashka-lanterna/blob/main/src/pod/babashka/lanterna.clj#L158-L175
it has some read/write functions in the injected bb pod code that serialise the data to be sent to the pod eg https://github.com/epiccastle/bbssh/blob/main/src/bb/pod/epiccastle/bbssh/output_stream.clj#L28-L45
and these are wrapped into java stream objects on the bb side using proxy
so that other bb code like the process code can use them eg https://github.com/epiccastle/bbssh/blob/main/src/bb/pod/epiccastle/bbssh/output_stream.clj#L60-L75
In the pod, these are hooked into the read/write methods of the stream objects on the pod side
and you don't want to halt the pod message processing mainline. So I used some metadata to annotate these blocking functions so I could handle them specially in the pod message core loop. Here you can see a ^:blocking
call. https://github.com/epiccastle/bbssh/blob/main/src/clj/pod/epiccastle/bbssh/pod/byte_array_input_stream.clj#L44-L60
These special cases are handled here https://github.com/epiccastle/bbssh/blob/main/src/clj/bbssh/impl/pod.clj#L206-L236
there is also an ^:async
annotation. For data coming back, you want to run things on the pod side, and have it send data back to your bb mainline at some later point. These async annotated functions implement this "callback" situation using bb pod async calls. These are used in the constructors for the pod side stream proxy eg https://github.com/epiccastle/bbssh/blob/main/src/clj/pod/epiccastle/bbssh/pod/input_stream.clj#L65
and the actual firing of those pod initiated callbacks (sending streaming data from the pod to bb on demand) is handled in this little namespace https://github.com/epiccastle/bbssh/blob/main/src/clj/pod/epiccastle/bbssh/pod/callbacks.clj
It is fairly tricky, but once all this is in place, streaming works in both directions.
Thanks you for this extensive explaination @U1QQJJK89
Sounds like it was quite an undertaking to get this working
I’ll study what you did, but I think I’ll postpone my idea a bit. So far it was just a nice to have, maybe this will change later
Yeah i was thinking of wrapping another process in a pod, send some commands to it, and then tail the results
right, you can do that just with async functions in the pod. (This is how streams from the pod to bb are implemented in bbssh) https://github.com/babashka/pods#async
Ah cool, might be worth a try. Thanks!