Fork me on GitHub
#clojure
<
2023-08-08
>
Old account06:08:40

Hello. Anybody could help me creating a driver for Metabase?

igrishaev06:08:41

As far as I understand, Metabase Client is about calling HTTP endpoints with JSON: https://www.metabase.com/learn/administration/metabase-api

igrishaev06:08:37

If you share your problem perhaps the community might help you

2
dpsutton12:08:56

The message is deleted so I cannot help. But I work at Metabase and could probably answer your question if I knew what it was

afry14:08:45

Hi everyone! I've got a library/framework question. I've been super intrigued with this common lisp library, and have been trying to hunt down a Clojure equivalent if it exists: https://github.com/rabbibotton/clog. The basic idea is that a backend server running common lisp serves up a web page. Instead of writing event handlers and javascript on the frontend to handle interactivity and DOM changes, events are streamed back to the backend server over a websocket connection. The code that handles those events is processed on the backend server, and any HTML or content changes are streamed back to the website in response. Does anybody know of a Clojure-based "streaming HTML" library like this?

Noah Bogart14:08:29

maybe check out Eletric Clojure by the fine folks at #C7Q9GSHFV?

🚀 2
jjttjj14:08:00

I haven't used htmx or this clojure library wrapping it https://github.com/whamtet/ctmx but I think that's in the same vein. Also it's not exactly what you're describing and may not be ideal for that use case, but https://github.com/hyperfiddle/electric is an interesting take on backend/frontend app development that might be worth checking out if you haven't heard of it (@UEENNMX0T beat me to this 🙂)

afry14:08:47

Electric looks like what I'm after! The thing that really interested me about CLOG is the potential to make a reactive app and to keep all of the functionality on the server, I will check it out 👍 And what a fantastic git repo and set documentation and examples. Well done Hyperfiddle

👏 2
jjttjj15:08:53

One thing about electric is that once you have a the project setup, it's my favorite backend+frontend development experience. But I think it's worth mentioning that what's nice about "totally backend driven frontend" like the Clog thing you posted (at least this is my impression, I haven't used it) is that it spares you from having to think about the frontend/js it at all, you're completely in "backend land". With electric you ARE making your project into a clj+cljs project and you are responsible for the cljs compilation of your app, and the web serving. You do get full client control in cljs which can be nice or necessary, and very seamless client/server integration. But still a clj+cljs app is IMO a ton more complex to develop and use than a pure clj, due to the compilation step, multiple contexts, etc. Just seems worth mentioning because Clog seems like the goal is "I don't want to have to think about the client I just want to get a webpage" while electric currently is more about how to best build a full stack clj+cljs app once you're committed to doing so.

tatut15:08:03

My Ripley is HTML live updates via websockets. It doesn’t have a ui widget library as such.

tatut15:08:24

Closer to phoenix liveview

afry17:08:26

After looking at the docs and examples, you're right in your assessment @U064UGEUQ. Seems like the complexity is a little reduced compared to setting up two separate CLJ + CLJS projects, just being able to work in one environment or one file for everything is a huge win in my book. Maybe I'll write my own CLOG for Clojure if it gets to be too much still 😛

tatut17:08:06

Ripley (as well as other “everything on the server” do have tradeoffs as you need a constant connection, but you can get radically simpler apps for many cases. I for one dislike working with the js ecosystem, so a single Clojure app is my preference.

tatut17:08:49

(shameless plug) here’s some examples of Ripley apps: https://github.com/tatut/xtdb-inspector and https://github.com/tatut/REPLey (also check out the examples folder in the ripley repo)

👍 2
afry17:08:15

Very cool demos @U11SJ6Q0K, I'll clone some of them and check them out. Good to know the library author is on slack for possible debugging help too 😉

tatut17:08:56

I am eating my own dogfood and using the library to do “real work”

💯 2
Jakob Durstberger17:08:33

Does anyone know of a clojure function or lib that helps with reading a file that continuously is written to? In this case, it is a log file with one log entry per line. I want to monitor the log files and parse new entries.

p-himik17:08:48

Don't know of any Clojure libs but I'd use whatever Java can give me. Just in case, the query for online search is "tail -f" (note the double quotes).

Jakob Durstberger17:08:31

With hawk I'd still have to manage how far I have read the files so far, right?

Jakob Durstberger17:08:48

> Don't know of any Clojure libs but I'd use whatever Java can give me. Just in case, the query for online search is "tail -f" (note the double quotes). Interesting. I might just be able to use that with the new clojure process api.

p-himik17:08:43

Oh, I didn't mean to use the tail exe directly. :) I meant that people would most often search for something like "tail -f" in java and there should be some answers on how to do it with some Java library or maybe even built-in JDK stuff.

phronmophobic17:08:27

if you do go with the process API, you might want tail -F.

👍 2
2
Jakob Durstberger17:08:57

> Oh, I didn't mean to use the tail exe directly. 🙂 Gotcha! Yeah, I already found the Watcher API added in Java 7. I just hoped there might be something that works on a per-file basis not just directory. But the comments so far are already helpful

Jakob Durstberger17:08:11

In case you are interested, this works pretty well so far.

(defn create-file-reader
  [^File log-file]
  (let [process (process/start "tail" "-F" (.getAbsolutePath log-file))]

    (async/go
      (let [scanner (Scanner. ^InputStream (:out process))]
        (while (.hasNextLine scanner)
          (println (.nextLine scanner)))))

    process))
Also already played around with putting the read lines onto a channel which is also super easy

p-himik17:08:13

You shouldn't use go here since .hasNextLine is blocking. I'd use a plain future or, if you need core.async, thread inside that go.

Jakob Durstberger17:08:24

Sorry, I don't understand. Is it not okay to wait for blocking functions in go? My core.async knowledge is .... lacking. 😅

p-himik17:08:30

Without thread it is not OK indeed - check out the docstring of async/go.

2
Jakob Durstberger17:08:03

Ah okay. So indefinitely blocking a go block is bad. So this is better

(async/thread
      (let [scanner (Scanner. ^InputStream (:out process))]
        (while (.hasNextLine scanner)
          (handler-fn (.nextLine scanner)))))

Jakob Durstberger17:08:45

Sorry, switched the plain println to a handler-function that does something with the read line.

Jakob Durstberger17:08:26

or just (future ....)

vncz18:08:03

Is Pedestal still the go-to for HTTP Server or is there anything else that should be considered?

tatut18:08:02

I use http-kit for all my stuff

👍 4
p-himik18:08:07

Pedestal is much more than a server. Depends on what you need. If you need many things that Pedestal offers and you already know Pedestal, I wouldn't look at anything else. If you need something simple then perhaps plain Ring with e.g. Jetty will suffice.

vncz18:08:38

It's mostly a small PoC, 2-3 endpoints, JSON parsing

p-himik18:08:25

In that case, I'd go with something minimal. Any web server will do, it doesn't sound like you need the absolute maximum of throughput or some advanced features. Http-kit is also a fine choice, IIRC it's easier to set up than other servers since it's native to Clojure. With 2-3 endpoints I wouldn't even use a routing library.

👍 2
hiredman18:08:38

my little one off stuff tends to look like https://downey.family/p/2023-08-08/whynter.cljc.html which uses undertow as the webserver, and relies on its built in routing stuff, and does some tricks to bundle a deps file, clojure source and clojurescript source all in one file

Joshua Suskalo18:08:14

http-kit is one of the better ones but it lacks some tooling for introspection that might be desirable depending on your usecase. I think @U04V70XH6 has recommended just using the ring netty adapter in the past because netty has really good tooling for introspection from the java world?

Joshua Suskalo18:08:15

That would mostly be relevant in high-volume cases though, if it's just for a hobby project or something just go with what's easy to grok for you.

👍 2
seancorfield19:08:14

http-kit is not great from an observability standpoint because it's "non-standard". At work, we use https://github.com/sunng87/ring-jetty9-adapter which is actually Jetty 11 under the hood (despite the name). Using standard Ring and its Jetty 9 adapter is fine for a small p.o.c. project but Jetty 9 is EOL in terms of any support and Ring's adapter isn't likely to get updated so the sunng adapter is the way to go as far as I'm concerned.

seancorfield19:08:51

(we used http-kit for a while in production -- it's great, but New Relic doesn't support it so you don't get good metrics coverage on it)

👍 4
phill22:08:41

https://github.com/eclipse/jetty.project/issues/7958 clarifies that Jetty 9 still receives security fixes and will continue to receive them until after the last paying Webtide customer has migrated off Jetty 9. (Date unknown.) So the solution is pretty simple actully. What we need is for a benefactor (such as Bill Gates) to subscribe to Webtide, in perpetuity.

2
phill22:08:19

But in answer to OP's question, I like Pedestal. Pedestal is pleasant for small projects (like its own tutorial) and presumably works for bigger things too. There is something to be said for using the same hammer for all nails, and Pedestal is very flexible in that sense. Also, I like having it underpinned by something that speaks the CVE lingo, like Jetty.

👍 4
didibus06:08:56

+1 to http-kit, especially for hobby projects, that's what I tend to use

didibus06:08:49

For web framework, both pedestal and ring are fine

Joe R. Smith13:08:34

My two cents, you can get pedestal up and running in a dozen lines of code and it's something you can easily grow into. I'd start there (http://www.pedestal.io has good getting started docs).