Fork me on GitHub
#babashka
<
2022-10-06
>
borkdude15:10:25

Great news everyone: two pods have recently been archived in favor of bb-compatible libraries: • pod-babashka-etaoin -> https://github.com/clj-commons/etaoin • pod-babashka-aws -> https://github.com/grzm/awyeah-api

🎉 9
Ian Fernandez15:10:56

There was some babashka tooling for converting project.clj to deps.edn, which is it?

Ian Fernandez15:10:34

I'll have a troublesome time to migrating a lein-monolith to this haha

borkdude15:10:18

Not sure how that works, but you can convert each subproject and then add them to the parent using local/root

👍 1
Ian Fernandez15:10:57

yeah I was thinking on that

grzm15:10:39

Using babashka/process, is there an idiomatic way to test whether the process is complete without blocking? I’ve got a case I want to read the first couple of lines of output from a long-running process and then quit without waiting for it to complete. What I’ve got right now is this (which seems to work):

(def sleeper (process/process "sleep 10"))
(def proc-future (future (.waitFor (:proc sleeper))))
(future-done? proc-future)
;; => false

;; confirming :exit hasn't been set, which of course it won't until sleeper is deref'd
(:exit sleeper) 
;; => nil
 
;; Here's where I'd be reading from (:out sleeper), which in the real world is doing more than just sleeping

;; wait
(future-done? proc-future)
;; => true

;; as expected, :exit is still nil
(:exit sleeper) 
;; => nil  

;; now I get exit
(:exit @sleeper)
;; => 0

grzm15:10:07

If there’s a more appropriate channel/forum for this question, please point me in that direction 🙂

grzm15:10:42

The reason I want to test if it’s complete is to check if it’s errored out early: waiting for the lines takes time itself and I’d prefer not to wait.

borkdude16:10:48

@U0EHU1800 We have :exit-fn now, a 1-arg function which is called upon process completion

borkdude16:10:04

Would that help?

borkdude16:10:28

E.g. you can fulfil a promise in that function and then block on the promise, while doing other work

grzm16:10:21

I don’t think :exit-fn would work: I explicitly don’t want to have to wait for process completion: I just want the first few lines of output.

borkdude16:10:40

E.g.:

$ bb -e '(babashka.process/shell {:exit-fn (fn [_] (prn :exit))} "sleep 1") nil'
:exit

grzm16:10:49

(but I want to know if it exited early, before those lines of output would complete)

borkdude16:10:01

Well, you can do that, with InputStream#available I think

grzm16:10:25

Yeah, I read from the InputStream (omitted in hopes of clarity)

borkdude16:10:04

Inputstream#available is non-blocking

grzm16:10:51

The specific example is a call to aws ecs deploy , which will do some processing (which can take some seconds), echo the id of the deployment, and then wait for the deployment to complete, which can take 5 or more minutes. I just want to wait long enough to get the id; but if it exits earlier due to some failure, I don’t want to even wait for the id, or set some arbitrary timeout.

borkdude16:10:17

yes: available ;)

borkdude16:10:54

you could also do some core.async magic with a timeout channel, etc

borkdude16:10:03

and then kill the process if you have a timeout

grzm16:10:06

Ah, and here I was looking at the JDK 7 Process docs. isAlive is exactly what I was hoping was there.

grzm16:10:16

And it is, in JDK 8.

borkdude16:10:31

PR welcome to clojurify that :)

grzm16:10:08

A function with two arguments, or a function that takes a map?

pizzaspin 1
lread16:10:11

Oops maybe I’ve been affected by #C0459PCHLTW

borkdude16:10:24

A function of the process (record) I would say?

😜 1
borkdude16:10:54

This is a different API question than the other thing we discussed. It's callback functions that you can't ever change the arity of, this isn't the same for regular functions.

borkdude16:10:59

Even though you are joking: don't get me started on introducing breaking changes :P

borkdude16:10:43

I feel the wrath of Rich even though he doesn't know me

lread16:10:18

Benevolent dictators for life can have that effect.

shem18:10:16

I have a etaoin script, using the old add-deps method. with the new system, do I need two files, the script and a bb.edn file?

borkdude18:10:00

@shem You can still use add-deps if you want

shem18:10:15

ok. it's maybe handier in this case because i have several scripts in the same bin directory, each with different dependencies