Fork me on GitHub
#beginners
<
2018-08-28
>
hawari04:08:28

anybody know a good circuit-breaker library for clojure? I've tried to use Hystrix wrapper but it's not quite compatible with my use case

Saikyun10:08:48

@hawari.rahman17 what do you mean by circuit breaker?

deg10:08:25

I'm smiling happily! I just found a useful little function that's been in Clojure since 1.0! not-empty. The name is not wonderful (IMHO), but it will clean up a lot of my string manipulation and javascript interop code.

hawari10:08:34

@saikyun I want to set up a mechanism so that whenever one of my application dependencies hang (usually another service), it should fail gracefully with some sort of fallbacks

hawari10:08:08

Hystrix is one of good example of what I want to do. Currently what I have is just a simple timeout and retry limit to a network call.

hawari10:08:42

If a service seems to be inactive, the app shouldn't bother to do any request to that service at all.

Saikyun10:08:19

@hawari.rahman17 oh, I see 🙂 I thought you meant on a function level, not application level.

Saikyun10:08:28

then I have no clue, sorry

hawari10:08:30

No problem, I've actually found some libraries like https://github.com/sunng87/diehard, I just want to ask around for opinions on this topic

timmyjose12:08:59

Hey guys, back again with the same problem (`lein repl` not working on macOS)

timmyjose12:08:23

I had posted the query a day back and I thought it had started working on its own, but I found what the real issue is

timmyjose12:08:39

If I invoke lein repl from a non-project directory, it spawns it up

timmyjose12:08:54

However, if I invoke the same command, it fails with this error message -

timmyjose12:08:14

Exception in thread "Thread-1" java.io.IOException: Cannot run program "/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home" (in directory "<elided>): error=13, Permission denied

timmyjose12:08:36

I had created the project using lein new by the way

manutter5112:08:24

Wait, JDK 11? Is that even released yet?

timmyjose12:08:22

Ah, that is the EA version... OpenJDK

timmyjose12:08:39

The same issue with JDK 8 as well though... I think it is a mac-specific issue

timmyjose12:08:00

I tried putting in a dummy :main in project.clj and tried lein run - same error 13

manutter5112:08:45

if you type echo $JAVA_HOME what do you get?

timmyjose12:08:52

$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home

timmyjose12:08:19

These are all the JDKs on my machine:

timmyjose12:08:20

$ /usr/libexec/java_home -V Matching Java Virtual Machines (3): 11, x86_64: "Java SE 11-ea" /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home 9, x86_64: "Java SE 9-ea" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home 1.8.0_112, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

timmyjose12:08:54

if I try from a non-lein-project directory, I get the REPL up:

timmyjose12:08:56

$ lein repl nREPL server started on port 49454 on host 127.0.0.1 - <nrepl://127.0.0.1:49454> REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 11-ea+8 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e user=>

timmyjose12:08:21

So currently I am simply starting it like that, and connecting from Cider on Emacs... but it's very irritating

manutter5112:08:29

I think the first thing I’d do is point JAVA_HOME back to jdk-8, looks like the others are Early Access

timmyjose12:08:46

I did try that, but let me reconfirm and get back here!

👍 4
manutter5112:08:38

Yeah, get the stable version working first, then once the environment is reliable, play with the EA stuff

timmyjose12:08:13

$ lein repl Exception in thread "Thread-1" java.io.IOException: Cannot run program "/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home" (in directory "<elided>"): error=13, Permission denied at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620)

timmyjose12:08:27

This is very bizarre indeed!

manutter5112:08:13

What’s your JAVA_HOME now, exactly?

timmyjose12:08:14

I am beginning to think this is some strange config issue with macOS, or maybe my mac with leiningen?

timmyjose12:08:24

$JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

manutter5112:08:32

Something definitely seems odd

manutter5112:08:56

Actually, I think if it were me, I’d try deleting leiningen and re-installing it

timmyjose12:08:57

I set it in my .bashrc ... for lein, I have set it in the ~/.lein/profiles.clj ... do you think removing that profiles.clj file might be worth a try?

timmyjose12:08:07

Thanks for your help and time, by the way... much appreciated! 🙂

manutter5112:08:50

Yeah, actually maybe move the profiles.clj file to disabled_profiles.clj for a bit

manutter5112:08:01

before re-installing lein

timmyjose12:08:10

Okay, let me try that and see... and btw, if this helps, I installed leiningen using homebrew

manutter5112:08:09

Hmm, never tried using homebrew to install leiningen

timmyjose12:08:11

I renamed the profiles file and tried lein repl, got a different error now -

timmyjose12:08:11

$ lein repl #error { :cause Don't know how to create ISeq from: java.lang.Character :via [{:type java.lang.IllegalArgumentException :message Don't know how to create ISeq from: java.lang.Character :at [clojure.lang.RT seqFrom RT.java 542]}] :trace [[clojure.lang.RT seqFrom RT.java 542] [clojure.lang.RT seq RT.java 523]

manutter5112:08:12

if moving profiles.clj out of the way doesn’t help, I think I’d use brew to uninstall lein, and then reinstall it with the instructions from http://leiningen.org

👍 4
timmyjose12:08:31

Yes, I think that makes sense... let me try that out and see!

timmyjose12:08:08

Phew... that worked at last! 🙂 ... I installed the lein script for that link and now lein repl works fine, and I can use Cider to spawn the REPL... thanks for your help, mate!

manutter5112:08:29

Awesome, glad that worked 😄

🙂 4
Markus Åkerlund Larsson13:08:32

I'm using Cursive. If I load a Clojure namespace in he repl and it requires another namespace, it works just fine. If I load a Clojurescript namespace that requires another Clojurescript namespace it won't resolve unless I first load the required namespace manually. Is it supposed to work like this or am I doing something wrong?

ben16:08:40

Is there an existing, easy way to read a csv (with a header) into a coll/seq of maps (keys defined by column names)?

ben16:08:53

org.clojure/data.csv seems fine but would require a couple of extra steps to wrangle it into the format I’d like. Seems like it’s probably something other people have come up against and solved already?

Patrick Hildreth19:08:33

Has there been any discussion involving contributions to this repo: https://github.com/danistefanovic/build-your-own-x

Patrick Hildreth20:08:03

I think it’s a great opportunity to showcase clojure in different use cases

mark_d20:08:56

Greetings, I’m new to clojure and I’m looking at the java.jdbc library. I’m trying to validate a jdbc connection string like “jdbc:<mysql://root:@localhost:3600/som>” but I can’t seem to find the best way to do it with the current version of java.jdbc. I’m following the O’Reilly Clojure book and the chapter (14) on jdbc mentions that the function jdbc/with-connection would do the trick. Unfortunately, I can’t seem to locate that api in org.clojure/java.jdbc “0.7.8". Is there a recommended way to validate a jdbc connection string?

mark_d21:08:29

Right now I’m using a trivial query to validate a db-spec:

(def db-spec {:classname "com.mysql.cj.jdbc.Driver"
              :dbtype "mysql"
              :dbname "som"
              :user "root"
              :useSSL false
              :password ""})

(deftest test-connection
  (testing "a local connection using db-spec"
    (is (= 15 (:result (into {} (jdbc/query db-spec ["SELECT 3*5 AS result"])))))
    )
  )
However, passing the connection string will throw an exception:
(deftest test-connection2
  (testing "a local connection using db-conn"
    (is (= 15 (:result (into {} (jdbc/query db-conn ["SELECT 3*5 AS result"])))))
    )
  )
Exception looks like:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
 at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException (SQLError.java:174)
    com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException (SQLExceptionsMapping.java:64)
    com.mysql.cj.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java:832)
    com.mysql.cj.jdbc.ConnectionImpl.<init> (ConnectionImpl.java:456)
    com.mysql.cj.jdbc.ConnectionImpl.getInstance (ConnectionImpl.java:240)
    com.mysql.cj.jdbc.NonRegisteringDriver.connect 

manutter5121:08:34

Are you sure you have the right port in your connection string? MySQL is usually listening on port 3306 not 3600.

manutter5121:08:30

Hey, at least it’s an easy fix ;D

👍 4
mark_d21:08:44

Yep, that’s it. Good eye!

mark_d21:08:20

I think I have a partial answer to “Where did with-connection go?” right here: https://stackoverflow.com/questions/22586804/with-connection-what-happened