Fork me on GitHub
#babashka
<
2022-02-10
>
Steffen Glückselig10:02:06

Concerning dependent tasks: Am I right in that the return-value of a task can be accessed via its name in the :depends-array - like -jar-file in

jar {:depends [-target -jar-file]
     :task (when (seq (fs/modified-since -jar-file
                                    (fs/glob "src" "**.clj")))
             (spit -jar-file "test")
             (println "made jar!"))}
?

borkdude10:02:15

Correct

🙂 1
🚀 1
teodorlu11:02:28

Idea. When running multiple babashka tasks in parallell, I'd love to see a prefix + coloring to differentiate between output from the different parallel processes. I think Docker Compose does something similar. Kind of hard to know which log line is from with process otherwise. Not sure if this makes sense to provide as functionality from the task runner itself, or if it can just be a "wrapper" / "function" / something in "userspace" that we could write and change ourself.

1
borkdude11:02:49

Good idea, but not sure how feasible this is. This requires several changes on several levels. All printing to stdout should be intercepted from normal println as well as processes invoked with babashka.process, clojure.java.shell, ProcessBuilder, etc.

jkxyz11:02:07

I would love to be able to replace foreman with babashka

borkdude11:02:43

That's kind of the idea of parallel tasks :)

❤️ 1
jkxyz11:02:55

Yes I've been meaning to use parallel tasks in some smaller projects. But at work I use foreman for running databases and it can get quite chatty in the logs, so the colored output helps. The Procfile runs 2 apps and 3 DBs and it needs various env vars set to work correctly, which would be cleaner if it was just a babashka task or script

borkdude11:02:20

As a current solution: possibly there is a bash/unix programs which can prepend the output of a process with some prefix/color, which you can then use to compose in babashka.process?

👍 1
borkdude11:02:39

I guess this works:

yes | while read line; do echo "[ERROR] $line"; done
and you could wrap that while read in a babashka script even.

jkxyz11:02:46

Will give that a try. Of course I could just consume the output of the process and prepend to each line. Since the --config flag was added I've been meaning to give that a try

borkdude11:02:09

I think you could solve this at the babashka process level by manually handling the output, although it would be nice if babashka process had something like this built-in. (process ["foo" "bar"] {:color :green :prepend "FOO"})

borkdude11:02:41

and then shell in tasks could also have that (since it's just a wrapper around process)

borkdude11:02:04

that would be a good first step I assume

jkxyz11:02:21

Will add some discussion to that issue 🙂

teodorlu12:02:46

Here's a snippet from what I'm doing right now. frontend is a normal bash function that runs the frontend. Essentially, with_prefix is meant to be used as a pipe that takes either stdout or stderr as input, and "colors and adds prefixes" as required.

teodorlu12:02:14

(sorry I kind of fired off a question and went dark, I have a hard time keeping focus on what I'm working on right now unless I turn off Slack)

borkdude12:02:49

@teodorlu Awesome, yeah, that's kind of what would become an option in babashka process (and could be done manually now by processing lines of output in babashka process).

👍 1
teodorlu12:02:22

I would be very happy if I could delete all that bash and replace with a bb.edn 🙂

borkdude12:02:22

Thanks for brainstorming :)

teodorlu12:02:36

Happy to chime in when I can ❤️

teodorlu13:02:47

Quickly skimmed the https://github.com/babashka/process, really like the process, deref and check API. Intresting fusion of unixy and lispy design.

❤️ 1
slimslenderslacks20:02:06

@teodorlu regarding use of color in bb output, I remember seeing that @lee did something cool in rewrite-clj with :enter and :leave tasks where every task got a nice colorized task started, task done. https://github.com/clj-commons/rewrite-clj/blob/main/bb.edn#L13-L14. Your questions reminded me of that.

👀 1
👋 1
teodorlu20:02:07

Nice! Thanks for letting me know, this is interesting.

lread20:02:39

My eyes are old. They need this kind of thing now! 🙂

isak21:02:09

What I do is bb some-file.clj | puget - this works great if your babashka script outputs edn data

isak21:02:42

But maybe that is a different use case

lread01:02:05

Yeah, https://github.com/lread/status-line is really just targeted for creating heading, warnings, and errors that pop out.

👀 1
1