Fork me on GitHub
#babashka
<
2024-01-23
>
martinklepsch08:01:00

Often during dev I need to run multiple commands in parallel. I know that I can achieve this with :depends-on and :parallel but I was just wondering if in the meantime other utilities for this emerged? Ideally without the need to define tasks / their relationship?

martinklepsch08:01:52

Maybe this could be a useful addition to bb.process. Like a little utility that takes multiple shell invocations and waits for them to exit or kills remaining ones when one exits.

borkdude08:01:36

You can do this with babashka.process/process + babashka.process/check

borkdude08:01:42

$ bb -e "(require '[babashka.process :as p]) (defn sleep [] (p/process {:inherit true} \"bash -c 'sleep 1; echo done'\")) (def p1 (sleep)) (def p2 (sleep)) (p/check p1) (p/check p2) nil"
done
done

馃憤 1
馃挕 1
martinklepsch11:01:17

thanks, that is pretty close but lets say p2 terminates with non-zero exit code, p1 would still keep running. Ideally I'd want to run multiple processes and just kill all of them if one fails. looking at the bb.process docs maybe the promesa integration could be used to make this work

馃憤 1
borkdude12:01:43

That's exactly how I did it in babashka tasks, only there I used core.async. Could have used a more manual solution as well. There's also a callback you can use whenever a process is finished and using this callback you could fulfill a (promise) in case of an error and then kill all other processes

imre11:01:51

I have a project where I want to use bb tasks to kick off different test scenarios. Most of these involve starting a clojure process with kaocha, but I also want to kick off a babashka-native kaocha run. The latter needs kaocha as a dep for the task. Is there a way to make only that single task dependent on kaocha somehow? Or is there a better way to handle this?

borkdude11:01:27

Yes, each task map can have :extra-deps

imre11:01:38

Oh for sure, how could I have missed that in the book???

imre11:01:46

Not enough caffeine

imre11:01:49

Thank you

borkdude11:01:10

no problem :)