Fork me on GitHub
#babashka
<
2022-11-03
>
oly12:11:28

struggling with my searching, I have a bb.edn with some tasks I want to create a tasks.clj and put some of the code in functions, do i need a deps.edn for this or can i just require the file in some way ? or how best to seperate the code so bb.edn does not end up massive

borkdude12:11:22

@oliver.marks The way to do this is: • Create a directory where you put the code, e.g. bb/tasks.clj • Add :paths ["bb"] to your bb.edn

borkdude12:11:56

• Then require tasks or so you in your bb.edn

oly12:11:14

ah I have it in the root currently, I will give that a try thanks for the awesome support 🙂

borkdude12:11:15

• And use the function: (tasks/whatever-fn)

borkdude12:11:35

If you want to have it in the root, it can stay there. Then add :paths ["."] to bb.edn to add the root dir to the classpath

oly13:11:43

works a treat, :paths was the missing piece 🙂

👍 1
shaunlebron15:11:33

Is there a way to see which babashka task is running?

borkdude15:11:01

yes, this can be seen with the (current-task) function

shaunlebron15:11:30

thanks. we got a big chain of dependent tasks running, and I’d like to see the task name printed. is there a builtin verbose option for this?

borkdude15:11:04

There is an example in the book:

{:tasks
 {:init (def log (Object.))
  :enter (locking log
           (println (str (:name (current-task))
                         ":")
                    (java.util.Date.)))
  a (Thread/sleep 5000)
  b (Thread/sleep 5000)
  c {:depends [a b]}
  d {:task (time (run 'c))}}}

❤️ 1
borkdude15:11:24

There is no built-in verbose option

shaunlebron15:11:14

oh, thank you!

shaunlebron15:11:09

Ah, I see it documented here now: https://book.babashka.org/#_run

shaunlebron16:11:57

what I settled on:

:init (def log (Object.))
:enter (locking log (println "[bb tasks] Started:" (:name (current-task))))
:leave (locking log (println "[bb tasks] Finished:" (:name (current-task))))

borkdude16:11:53

makes sense

wilkerlucio17:11:44

Im wondering why we need this locking part?

shaunlebron17:11:48

i assumed it was to prevent printers from parallel tasks from crossing streams

👍 1
borkdude18:11:30

yes. you could also use timbre which already does this

borkdude18:11:36

(timbre is built-in logger)