Fork me on GitHub
#babashka
<
2022-10-26
>
Dimitar Uzunov12:10:44

So I have this code here where I want to follow a log for 30s and then stop a process, what am I doing wrong? it seems to run without stopping.

(let [tail-proc (babashka.process/shell "journalctl -f -u service-name")]
    (Thread/sleep 30000)
    (babashka.process/destroy-tree tail-proc))

Dimitar Uzunov12:10:16

this seems to work in the repl hmm

borkdude12:10:29

are you doing this in bb or clojure?

Dimitar Uzunov12:10:56

babashka v0.10.163

borkdude12:10:12

I think it should work the way you've written it

Dimitar Uzunov12:10:04

weird it does work fine in the repl, but I’m using this in a CI pipeline and there it doesn’t seem to notice 30s have passed

Dimitar Uzunov12:10:23

note my repl is actually connected to the same server as the CI agent

borkdude12:10:01

does it help if you do a little thread sleep after the kill?

Dimitar Uzunov12:10:57

no, no difference

borkdude12:10:11

does it work when you execute `

killall journalctl

Dimitar Uzunov12:10:20

(future (babashka.process/shell (str "journalctl -f -u service.nae"))
  (Thread/sleep 30000)
  (System/exit 0

Dimitar Uzunov12:10:43

luckily it is the last task in the pipeline 😄

borkdude12:10:03

weird, but if it works :)

Dimitar Uzunov12:10:27

you wanted to check if journalctl is a child process or something?

borkdude12:10:01

Another thing to try:

(.destroyForcibly (:proc tail-proc))
in your first example

Dimitar Uzunov12:10:13

trying that right now

Dimitar Uzunov12:10:11

yeah it doesn’t work

Dimitar Uzunov12:10:32

I guess (System/exit 0) it is 🙂

borkdude13:10:20

ok, then I'm also out of ideas :)

Daniel Gerson13:10:25

Probably done something stupid I can't see 😅, but I get a Could not find namespace: top.build.buildfor the following example https://github.com/dmg46664/problems/tree/main/05_bb_local_root

borkdude13:10:37

Seems like it should work right? I'll try locally ;)

borkdude13:10:22

This works, you don't need the require:

(exec 'top.build.build/justrun)

borkdude13:10:52

And then change justrun to a 1-arg function:

(defn justrun [_]
  (println "Hello world!"))

Daniel Gerson13:10:03

Thank re not needing require.

Daniel Gerson13:10:26

Never got as far as seeing the arity was wrong though 😅

Daniel Gerson13:10:59

Even though I have a workaround now, much obliged, it should have worked, no?

borkdude13:10:43

exec expects a fully qualified symbol of the function

Daniel Gerson13:10:04

Ah! that's what I didn't understand.

Daniel Gerson13:10:13

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Could not find namespace: top.build.build.
Location: <expr>:4:47

----- Context ------------------------------------------------------------------
1:
2:  ;; deps
3:
4: (ns user-f39cc2e2-32f4-4dd5-b013-7c98601c1be1 (:require [top.build.build :as build]))
                                                 ^--- Could not find namespace: top.build.build.
5: (require '[babashka.tasks #_#_:refer [log]])
6: (when-not (resolve 'clojure)
7:   ;; we don't use refer so users can override this
8:   (intern *ns* 'clojure babashka.tasks/clojure))
9:

----- Stack trace --------------------------------------------------------------
user-f39cc2e2-32f4-4dd5-b013-7c98601c1be1 - <expr>:4:47
I guess the above error could be better though?

borkdude13:10:05

I think so yes, feel free to post an issue about the error improvement

1
Daniel Gerson13:10:38

Is it a bug or a feature? 😆

rmxm13:10:29

I notice babashka, has clojure.data.xml but is there a simple way to use clojure.xml and just get a plain map out of xml source? (I am avoiding the 'zippers' stuff :)

borkdude13:10:12

clojure.xml is effectively deprecated in favor of clojure.data.xml. https://github.com/babashka/babashka/blob/master/examples/xml-example.clj is an xml example <- @roguas

🙌 1
richiardiandrea15:10:34

Hi there, I am trying to use org.jsoup/jsoup {:mvn/version "1.15.3"} in babashka - but I do not seem I can do it Is that the case? Are java dependencies usable from bb?

borkdude15:10:26

@richiardiandrea Correct, you can't use Java libraries in bb - only classes that are added at compile time are supported. This restriction doesn't apply for #C029PTWD3HR and Node.js libraries.

👍 1
borkdude15:10:45

@richiardiandrea There are various pods that you can use in bb to parse HTML though

richiardiandrea15:10:34

ok yeah, I'll have to investigate those - the problem is the code should be compatible for both bb and clojure- I'll have a look

richiardiandrea15:10:28

well unfortunately there is only one pod that does something similar to what we are doing...and I don't see html pods in the list, I'll dig more

borkdude15:10:41

@richiardiandrea There are two: jsoup and bootleg

richiardiandrea15:10:57

Oh ok I checked here https://github.com/babashka/babashka/blob/master/doc/projects.md#pods Do you want me to PR your link to the README?

borkdude15:10:52

yeah I think that would be good :)

richiardiandrea15:10:04

ok let me do that

borkdude15:10:15

Hm, it already has that right? > See https://github.com/babashka/pod-registry for an overview of available pods.

richiardiandrea15:10:07

oh I did not see that, I went all the way down to the main README here https://github.com/babashka/babashka#pods

borkdude16:10:47

Feel free to PR improvements :)

richiardiandrea16:10:27

yeah, where was your sentence taken from? It's not babashka/README.md right?

borkdude16:10:00

the exact link you posted earlier

richiardiandrea16:10:27

ok I am confused then, sorry - maybe I just missed it

richiardiandrea16:10:23

@j3k.walczak Hi, I am looking at https://github.com/vollcheck/pod-jaydeesimon-jsoup and I see that you have not enabled issues...I am wondering if you accept PRs against that project? We would like to add some stuff to it 😄

borkdude16:10:32

yeah, I think you were looking at a fork

👍 1
vollcheck20:10:26

hi @richiardiandrea I've unlocked things that were unlockable although bear in mind that as @U04V15CAJ said it's a fork with purpose to make it available in the pod registry really.

borkdude20:10:30

@richiardiandrea bootleg also has jsoup - don't know exactly what you're after though

richiardiandrea21:10:22

I am basically in need of using (.getErrors ^Parser parser) when Jsoup detects syntax errors

richiardiandrea21:10:16

This is usually done by sharing the parser, which you can pass down as last argument to Jsoup/parse