Fork me on GitHub
#babashka
<
2022-03-26
>
Eugen00:03:34

FYI clj-rss works with babashka, I made a PR with an example and deps.edn https://github.com/yogthos/clj-rss/pull/25 . So you can generate RSS feeds from directories using babashka scripts

🎉 1
rmxm19:03:30

quick question, is there any info somewhere on how to process posix signals? SIGTERM in particular?

borkdude19:03:25

@roguas In Java you can use use these classes for it:

(:import [sun.misc Signal]
           [sun.misc SignalHandler])
They are not exposed by bb to scripts right now, but some of it is available in babashka.signal: there is one function pipe-signal-received?

borkdude20:03:03

We could add more stuff to that namespace and/or expose the sun.misc classes -- but sun.* classes are actually considered implementation detail.

borkdude20:03:39

We could maybe add babashka.signal/on-sigterm or so

borkdude20:03:55

This probably needs some experimentation

rmxm20:03:01

gonna take a look, thanks... supporting SIGTERM seems pretty crucial to me, if you are running scripts as docker containers, this is de facto way to communicate from host os 🙂

borkdude20:03:02

I'm ok with exposing these classes, that seems to be the lowest level of friction since the internet has Clojure examples on how to do this stuff

borkdude20:03:28

and although they are implementation details, I think it's unlikely they'll ever deprecate these since unless the offer a more "supported" way

rmxm20:03:06

i would love not to go back to python, having discovered this missing piece 🙂

borkdude20:03:21

let me make a branch so we can test stuff

rmxm20:03:11

big thanks, really impressed 🙂 I think its really a must have if you plan on running inside docker/container, SIGTERM is part of normal lifecycle

borkdude20:03:46

so far nobody asked for it, although babashka has seen quite some docker usage

borkdude20:03:51

but I believe you :)

rmxm20:03:22

well, depends on the workload, but if you have a workload that has some cleanup (say close a connection to db) its good to do that, I am working on agent that would startup another job and this job has capability to susped and dump partial results... most people also do kill -9 to later stackoverflow why the thing broke down/left garbage 🙂

didibus04:03:07

For cleanup, you want to register a Runtime.shutdownHook, that's the preferred way to handle it in Java

rmxm20:03:14

if you give me some info on how to test the build, I am more than willing 🙂

borkdude20:03:10

Added it, and seems to work:

$ ./bb -e '(sun.misc.Signal/handle (sun.misc.Signal. "INT") (reify sun.misc.SignalHandler (handle [_ _] (prn :hello)))) (Thread/sleep 10000)'
^C:hello
^C:hello
^C:hello
^C:hello
^C:hello
A new binary will appear in #babashka-circleci-builds in the signal branch

❤️ 1
borkdude20:03:08

@roguas It's there now.

rmxm20:03:22

will take a look when back home, thanks again

borkdude21:03:08

merged to master now

emccue22:03:38

Maybe an obvious question, but is sun.misc.Signal actually exposed in the module graph?

borkdude22:03:49

I'm not sure exactly what this means, but jdk.unsupported sounds alarming ;)

didibus04:03:51

These classes are not portable between OS I believe, and are not considered part of the new Java API post Java 11 I think

didibus04:03:06

I think shutdownHook is what is supposed to be used for cleanup

borkdude05:03:53

Yep, posted that later in the channel. Thanks!

👍 1