This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-07
Channels
- # announcements (1)
- # babashka (31)
- # beginners (54)
- # biff (3)
- # calva (22)
- # cider (13)
- # circleci (1)
- # clj-kondo (6)
- # cljsrn (2)
- # clojure (113)
- # clojure-europe (58)
- # clojure-mexico (5)
- # clojure-nl (3)
- # clojure-uk (7)
- # clojurescript (81)
- # cursive (20)
- # datomic (33)
- # events (3)
- # fulcro (29)
- # introduce-yourself (1)
- # meander (78)
- # off-topic (60)
- # om-next (2)
- # podcasts (1)
- # re-frame (8)
- # reagent (5)
- # reitit (20)
- # remote-jobs (1)
- # shadow-cljs (24)
- # spacemacs (10)
- # sql (8)
- # tools-deps (22)
- # xtdb (16)
What is the most "babashka" way to do,
$ kill -9 `ps -ef|grep spring.main.banner|grep -v grep|cut -c9-17
`This seems to do the trick, but it is not winning in the readability category.... IMHO
(apply shell/sh (concat ["kill" "-9"] (map #(.trim %) (map #(subs % 9 17) (filter #(str/includes? % "spring.main.banner") (str/split (:out (shell/sh "ps" "-ef")) #"\n"))))))
like a lot of clojure code I write, if I go that long, I'd probably use threading (I swapped out some parts to match a repro I could spin up quickly):
$ bb '(->> (:out (shell/sh "ps" "-ef"))
str/split-lines
(filter #(str/includes? % "repl"))
(map #(subs % 9 15))
(map str/trim))'
A bit more verbose, but using pure Java:
;; destroy all nano processes of all users
(require '[clojure.string :as str])
(defn command [phandle]
(.orElse (.command (.info phandle)) ""))
(map #(.destroyForcibly %)
(filter #(str/includes? (command %) "nano")
(iterator-seq (.iterator (java.lang.ProcessHandle/allProcesses)))))
if that last expression is maybe better with mapv
or wrapped into a doall
to avoid laziness or if we don't care about which processes has been killed, then just run!
.
there might also be some caveat with .destroyForcibly
, if the process was not spawned by the current JVM process:
> The default implementation of this method invokes destroy() and so may not forcibly terminate the process.
Source: https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html#destroyForcibly--
@U086D6TBN I think they include that caveat since not all OSes may support all ops
there is also jps -l -v
, which already limits the process list to java processes and nicely prints their main class or with the -l
both the main package and class (if i understand it correctly)
✦2 $ jps -l | bb -i '(->> *input* (map #(clojure.string/split % #" ")) clojure.pprint/pprint)'
(["1729" "org.jetbrains.idea.maven.server.RemoteMavenServer36"]
["3553" "jdk.jcmd/sun.tools.jps.Jps"]
["3241" "clojure.main"]
["1594"])
i see it often that ppl shell out from bb. that makes a bb program more self contained, but it's also a lot more verbose, because it's likely that u want to do what bb -i
does anyway.
I'm working on getting clojure.data.json to work from source. I've discovered a bug when you generate a case expression in a macro :-D
i’m using the filewatcher pod to watch a couple of directories, but at the end of the script I need to do a (Thread/sleep somelargenumber) otherwise the script exits right away. Is there a cleaner way to pause indefinitely with out bb exiting?
Hey borkdude, any chance to have java.text.SimpleDateFormat
added to the Java classes available in bb? Sorry if this isn't the right place to ask this things
In bb the java.time
package is available, this is recommended to use over java.text.SimpleDateFormat
ah ok thanks
I'm very close to making babashka compatible with executing clojure.data.json
from source (not sure if this is really useful since bb already has a JSON lib, but why not). There is one last issue with clojure.pprint
and formatter-out
which is used in clojure.data.json
for pprint-ing JSON. In case anyone wants to help debug...
https://github.com/babashka/babashka/issues/922
The fork of data.json here: https://github.com/babashka/data.json runs with babashka's formatter-out
branch.
I'm calling it a night.
hello, whats the syntax to ask babashka to run a function given a namespace/fn-name?
similar to clojure -X
, I remember there was something like that, but can't remember what the command was like
You mean using tasks?
{:tasks
{
clean {:doc "Removes target folder"
:requires ([babashka.fs :as fs])
:task (fs/delete-tree "target")}
}
}
Then you can do a bb run clean
Ah wait there is this way https://book.babashka.org/#_invoking_a_main_function
I remember at the beginning of tasks (and maybe the feature got removed, not sure) there was some option to run any function from any namespace in the classpath (kinda like -X on clojure), trying to remember about that
oh, I guess there are two sections on "main function" on the docs, and the link got to the later, but the first seems to be what I'm looking for, using -m
yeah -m
it is: https://book.babashka.org/#main-function