Fork me on GitHub
#babashka
<
2022-03-03
>
xlfe04:03:36

Could anyone recommend a scheduling library for #babashka? I like the look of @jarohen's chime https://github.com/jarohen/chime but I get the following error

Could not find /home/vimuser/.deps.clj/1.10.3.1040/ClojureTools/clojure-tools-1.10.3.1040.jar
Downloading tools jar from  to /home/vimuser/.deps.clj/1.10.3.1040/ClojureTools
Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.pom from central
Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.pom from central
Downloading: org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom from central
Downloading: jarohen/chime/0.3.3/chime-0.3.3.pom from clojars
Downloading: org/clojure/tools.logging/1.0.0/tools.logging-1.0.0.pom from central
Downloading: org/clojure/pom.contrib/0.2.2/pom.contrib-0.2.2.pom from central
Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.jar from central
Downloading: org/clojure/tools.logging/1.0.0/tools.logging-1.0.0.jar from central
Downloading: org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar from central
Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar from central
Downloading: jarohen/chime/0.3.3/chime-0.3.3.jar from clojars
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: clojure.lang.IBlockingDeref
Location: chime/core.clj:4:3

----- Context ------------------------------------------------------------------
1: (ns chime.core
2:   "Lightweight scheduling library."
3:   (:require [clojure.tools.logging :as log])
4:   (:import (clojure.lang IDeref IBlockingDeref IPending)
     ^--- Unable to resolve classname: clojure.lang.IBlockingDeref
5:            (java.time ZonedDateTime Instant Clock)
6:            (java.time.temporal ChronoUnit TemporalAmount)
7:            (java.util Date)
8:            (java.util.concurrent Executors ScheduledExecutorService ThreadFactory TimeUnit)
9:            (java.lang AutoCloseable Thread$UncaughtExceptionHandler)))

----- Stack trace --------------------------------------------------------------
chime.core - chime/core.clj:4:3

xlfe04:03:27

The use case is as part of https://github.com/xlfe/radiale. The concept is the radiale babashka script runs as a service 24/7 (partially because as a home automation system, it has to manage state 24/7 - eg, sensor detects something, do something else) but I'd also like to be able to set timed actions too (eg. for example I want to turn on a light at the same time each day). So I'm looking for a scheduler that is happy within babashka. I could find a python one and interact with it through the pod framework, but I'm trying to keep as much in Clojure as possible (and chime looks nice!).,,

borkdude08:03:06

I think you could maybe rewrite chime in such a way that bb is happy with it. The problem is that (currently) bb can only reify pre-selected java interface(s), so this won't work: https://github.com/jarohen/chime/blob/fa0b6e8c0f68e6d6134aee6ba9eb2ce032ba65b0/src/chime/core.clj#L117 But if you could rewrite that using functions, that would work just fine.

borkdude08:03:30

This seems like something that could work: https://github.com/overtone/at-at/blob/master/src/overtone/at_at.clj Given that all the Java classes are in bb.

borkdude08:03:15

It seems that ScheduledThreadPoolExecutor is the most important one to add.

borkdude08:03:28

Another idea might be to use cron jobs directly

xlfe09:03:36

Thanks - at-at looks like it would do too. Yes I get

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.concurrent.ScheduledThreadPoolExecutor
Location: overtone/at_at.clj:2:3

xlfe09:03:12

Hmm. I don't see how cron jobs would work, without some kind of message bus? Because my babashka script is long-running, rather than being started each time

borkdude09:03:09

I mean, you could shell out to install cron jobs, but that might not be so nice.

xlfe09:03:00

Yeah. I think a python scheduler via the pod interface would be better than shell and cron!

borkdude09:03:24

I made a branch at-at where I added the necessary classes. Let's see how much binary size it adds. You can download the binaries from #babashka-circleci-builds to try out if this works.

borkdude09:03:52

It seems the binary size growth is pretty reasonable.

xlfe09:03:22

thanks! that was quick 🙂

xlfe09:03:54

I'll give it a whirl 🙂

xlfe09:03:11

That's looking like a winner

xlfe09:03:34

only 106kb added 😂

borkdude09:03:04

did it work for you?

borkdude10:03:59

40kb is coming from java.text.SimpleDateFormat which I resisted to add for a long time since java.time is the recommend way, but it has come up so many times now that I will just go ahead and add it ;)

borkdude10:03:17

merged to master

xlfe11:03:51

🙂 thanks!

borkdude11:03:04

at-at, a Clojure scheduling library, will become bb-compatible in the next release: https://twitter.com/borkdude/status/1499338195963678720

borkdude14:03:04

yes. already available with:

bash <(curl ) --version 0.7.7-SNAPSHOT --dir .

🙌 1
teodorlu16:03:12

Are there any examples of babashka being used as a pandoc filter? https://pandoc.org/filters.html

😃 1