This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-07
Channels
- # adventofcode (40)
- # aws (15)
- # babashka (76)
- # beginners (39)
- # calva (6)
- # cider (3)
- # clj-kondo (3)
- # clojure (89)
- # clojure-austin (1)
- # clojure-australia (4)
- # clojure-europe (42)
- # clojure-italy (9)
- # clojure-nl (27)
- # clojure-spec (8)
- # clojure-uk (17)
- # clojurescript (9)
- # conjure (1)
- # data-science (1)
- # datomic (19)
- # deps-new (4)
- # docker (9)
- # emacs (5)
- # events (1)
- # fulcro (36)
- # kaocha (31)
- # lambdaisland (5)
- # leiningen (3)
- # membrane (3)
- # nrepl (10)
- # off-topic (31)
- # pedestal (7)
- # reveal (47)
- # shadow-cljs (35)
- # sql (9)
- # test-check (1)
- # tools-deps (24)
- # uncomplicate (12)
- # xtdb (5)
If anyone here is using babashka on the cloud / serverless, you might want to reply here: https://www.reddit.com/r/Clojure/comments/k8fc5s/askreddit_have_you_tried_to_run_babashka_on_a/
It definitely would be more easy to do than to convert your clojure web app to be graalvm compatible
with latest Babashka, using babashka.process/process
, setting any :env
options map is causing command to fail
warnings can be silenced by the --no-warnings (-n) option
Assertion failed: (str1!= NULL), function add3strings, file string_utils.c, line 103.
not sure if I’m doing anything wrong, but only way script is working is by commenting out the env options. even an empty map causes that error@alidcastano I can't repro that on my machine:
user=> (slurp (:out @(babashka.process/process ["ls"] {:env {"FOO" "BAR"}})))
what is your repro and which OS? latest = 0.2.4?This works:
@(proc/process
["clj"]
{:inherit true
:env (merge (into {} (System/getenv)) {"FOO" "BAR"})
:shutdown proc/destroy})
I can reproduce the problem with this code:
(let [pb
(java.lang.ProcessBuilder.
["clj"])]
(.clear (.environment pb))
(.inheritIO pb)
(let [p (.start pb)]
(.waitFor p)))
It doesn't matter if you run this with bb or clojure
, you get the same error, which I think is coming from rlwrap@alidcastano I found out by experimentation that rlwrap apparently expects TERM
, HOME
and PATH
to be set correctly
hm should those properties be auto-included in env by babashka.process? or you think it’s better for user to explicitly set them?
This isn't a bb or process specific problem. rlwrap could maybe give better errors when these env vars aren't set
Seems like this should have been fixed with this: https://github.com/hanslub42/rlwrap/pull/80
> Why are you invoking `clj` and not `clojure` btw? bad habit, i tend to forget difference and end up using shorter version. but error does seem to happen for both commands
hmyeah, that needs at least PATH and HOME it seems. clojure
is a bash script which needs that
before using babashka process I was setting env vars like this, btw, which was not causing this error
(defn- set-process-env-vars
"Set env vars on process builder environment object."
[pb env-map]
(let [env-obj (.environment pb)]
(doseq [[k v] env-map]
(.put env-obj (-> k name str) v))
pb))
> Why not pass through all env vars? did not consider it. was mainly just passing the ones i knew i needed in my program
ok, we could document this better. So the preferred way when adding things to the current env, would be this:
:env (assoc (into {} (System/getenv)) "FOO" "BAR")
@alidcastano btw, your shutdown hook should be something like proc/destroy
or proc/destroy-tree
since the hook will receive a map
Hi! To patrice, I converting this following bash script: https://gist.github.com/mg6/7321d66ac93d9550322afd8aeec2789a
It's still a draft, I want to refactor a little bit.
Is it doseq
the best candidate for looping and print out in this case?
The Babashka version: https://gist.github.com/PrestanceDesign/7d5b8b577932f17660cdaf5b902e409c
Ok great, thank you @borkdude ! I'll create a PR to add in BB's examples dir
Cool. Can you use [skip ci]
in your commit message? Then CircleCI won't get triggered. This is good practice when adding docs/examples.
You might also want to do some error handling because on my macOS system the script doesn't work as expected.
Also a description what the script is for would be nice, since it isn't entirely clear to me who and why this is for
Yes, of course. In two words, the script allows you to define which DigitalOcean cloud datacenter (region) had best ping latency to take a server (droplet) on. Little bit, a cli version of this page: https://cloudpingtest.com/digital_ocean
If you look at the error message returned from clojure shell:
p\nApple specific options (to be specified before mcast-group or host like all options)\n -b boundif # bind the socket to the interface\n -k traffic_class # set traffic class socket option\n -K net_service_type # set traffic class socket options\n -apple-connect # call connect(2) in the socket\n -apple-time # display current time\n"
" => ms"
One minor mistake I notice is that it should be (shell/sh "ping" "-c" "5" "-w3" endpoint)
That doesn't fix it for me:
(defn ping-result [endpoint]
(let [{:keys [out err]} (shell/sh "ping" "-c" "5" "-w3" endpoint)]
(prn err)
(prn (str endpoint " => " (get-average out) "ms"))))
Not listed here: https://nixdoc.net/man-pages/FreeBSD/man8/ping.8.html So I guess it's a gnuism.
Right, that's a separate "it's wrong", but the impl of some pings may be lenient to it. (gnu's is)
#!/usr/bin/env bb
;; explicit requires
(require '[babashka.curl :as curl]
'[babashka.process :as p]
'[clojure.string :as str])
(def url " ")
(def get-endpoints
(let [{:keys [body]} (curl/get url)]
(re-seq #"speedtest\-.+." body)))
(defn get-average [result]
(-> result
str/split-lines
last
(str/split #"/")
(get 4)))
(def mac?
(str/starts-with? (System/getProperty "os.name") "Mac"))
;; TODO: test on Windows
(def timeout-arg (if mac? "-t3" "-w3"))
(defn ping-result [endpoint]
(let [out (-> (p/process ["ping" "-c" "5" timeout-arg endpoint]
{:out :string})
p/check ;; crash on non-zero exit code with error output
:out)
msg (str endpoint " => " (get-average out) "ms")]
(println msg)))
(doseq [endpoint get-endpoints]
(ping-result endpoint))
Hi @borkdude!
I have a question. I saw in your script version that you required explictily babashka.curl
and clojure.string
.
I thought that alias are already present in some of last bb versions, right?
Do you recommanded to always manually required?
This is why I advice to always use explicit requires. I think it is also more readable. The built-in aliases are for command line one-liners. See https://book.babashka.org/#style
Yes I use clj-kindo with Flycheck in my Spacemacs conf
OK, I understand, thanks! I also prefer when my linting is clean so now I go for the explicit requires 👍
Perfect!
Here they list the args that Windows accepts: https://www.howtogeek.com/wp-content/uploads/2018/06/x2018-06-20-8.png.pagespeed.gp+jp+jw+pj+ws+js+rj+rp+rw+ri+cp+md.ic.hG3nPp3yId.png https://www.howtogeek.com/355664/how-to-use-ping-to-test-your-network/
I just tested your updated version (with process) and I had this error
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message:
Location: /home/mike/Lab/Clojure/Babashka/digitalocean-ping.clj:25:13
----- Locals -------------------------------------------------------------------
endpoint: ""
Yes. Same error with the modified version.
Feel free to change back to clojure shell, this is just a way to trigger an error when there's something suspicious
OK I understand. 👍 FYI, the return code is 1
I'm on Linux Unbuntu.
If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. ... Otherwise it exits with code 0.
Maybe that's the case?Thank you for everything and your availability! I'll continue tomorrow.
Thx, goodnight. 🙂