This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-18
Channels
- # aleph (4)
- # beginners (70)
- # cider (66)
- # clara (16)
- # cljdoc (20)
- # cljs-dev (9)
- # cljsrn (2)
- # clojure (36)
- # clojure-ecuador (2)
- # clojure-italy (14)
- # clojure-japan (2)
- # clojure-nl (22)
- # clojure-uk (79)
- # clojurescript (133)
- # clojutre (2)
- # code-reviews (5)
- # cursive (5)
- # data-science (1)
- # datomic (47)
- # duct (2)
- # emacs (1)
- # figwheel-main (3)
- # fulcro (11)
- # funcool (1)
- # graphql (6)
- # hyperfiddle (4)
- # leiningen (4)
- # luminus (9)
- # lumo (8)
- # mount (4)
- # nrepl (2)
- # off-topic (19)
- # onyx (1)
- # re-frame (23)
- # reagent (91)
- # reitit (17)
- # ring-swagger (2)
- # shadow-cljs (43)
- # tools-deps (27)
- # vim (45)
Is there a way to gracefully close the source stream to (clojure.data.xml/parse input-stream)
without causing
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3157,54]
Message: Stream Closed
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
at clojure.data.xml$pull_seq$fn__16462.invoke(xml.clj:287)
(I’m calling .close manually in exception handling because I can’t wrap with with-open
in this case)rookie mistake here: figured out what I was doing wrong. the step that was attempting to to spool data off the parse stream was attempting to call first after the stream had been closed
HI guys, a simple question.
I use emacs with cider trying clojure.
After I add a dependency in project.clj file. Should cider-restart
download the dependency and re cider-jack-in
?
@namy.19 you can add dependencies without restart the repl with clj-refactor
. If you simply change the project.clj
file, you should restart the repl. when the repl started, it will download the dependencies, no need to restart twice.
@doglooksgood but when i run cider-restart
, there’s no new dependency in the ~/.m2 folder, and requiring new dependency in core.clj file won’t work.
I haven't use cider-restart
. usually I just C-c C-q
to close cider connection, and then C-c M-j
to jack-in again.
@doglooksgood Thanks! I’ll check clj-refactor
.
https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-project-dependency I think you are looking for this.
Just checked the cider-restart
function, seems it only reconnect the repl, not killing repl and restart it.
hi guys i am pulling some numbers from db using queries and i am constructing map like this
{:k1 (query1)
:k2 (query2)
...
that is pretty inefficient in my mind
and i had an idea instead of making 50 queries to get values for that map
to create massive query which would return map or list of values that i will bind to keys later on
is it possible to do something like that?
this might be more sql question than clojure onei am already something something like that i want do get all those values in 1 db call not in 50
select (select ...) as k1, (select ...) as k2, ...
strait forward solution but it is possible to optimize it later
depends on a queries that you are running
i was thinking of something like
(reduce
(fn [aggr row] (assoc aggr (:id row) (:value row)))
{}
(sql/select "select * from table limit 50"))
if some of them selecting identical data but transforming them differently you can place one query into from
block and apply different transformation functions in top select
sometimes just placing subqueries in one query can give some ideas how to optimize it
and in some cases subqueries can be optimized by DB engine itself )) (unfortunately, rare cases)
I'm trying to get a grip on logging. I've got a ring based app. The log is spammed with useless entries, I would love to be able to filter noise. One way to do that is by the log level, but I actually would like to filter out some info level messages while leaving others intact. Just for context, if I do
(require '[clojure.tools.logging :as log])
(log/info "Foo")
it logs it straight out to my repl. On heroku I use papertrail to access Iog messages.
Now, is there a way I can wrap the logger with a middleware like wrapper function?From a beginner perspective, the JVM logging story is sordid and awful. To avoid most of that I would suggest timbre instead of clojure.tools.logging: https://github.com/ptaoussanis/timbre The difference is that timbre is a logging system, not a wrapper that delegates to a usually java-native logging system. It also is plain clojure (clojure/clojurescript), not something that consumes an underlying java library. So one can do middleware stuff and formatting output and so forth in a more clojurey manner. And it has explicit whitelist/blacklist configuration. Modern Java libraries of course write their own logs; they can usually be implicitly made to have their logging go to timbre by adding to project.clj [com.fzakaria/slf4j-timbre "0.3.2"] Timbre itself is not trivial, there are a number of knobs to understand, and it's not the fastest logger nor necessarily the most ops-friendly. But I've found it to be a useful point of control and simpler to reason about.
Hi, I would like to check a good Clojure tutorial about CircleCi integration with tests, somebody know a similar repo on Github or a good blog post? (I read the CircleCI docs, I found) — mainly for Ubuntu (not Heroku)
the best place to start - https://circleci.com/docs/2.0/language-clojure/ and after that - check out how circleci frontend is integrated with itself) https://github.com/circleci/frontend/blob/master/.circleci/config.yml (edited)
I’m trying to deploy the default compojure-api app to openshift. I created the app like this: lein new compojure-api myapi
. I’ve only modified the handler statement to use port 8080: :ring {:handler myapi.handler/app :port 8080}
.
Questions:
1. where openshift examples call for deployment of a war file, should I be using something like this to produce the binary artifact: lein do clean, ring uberwar
?
2. The produced file seems to be called target/server.jar
, should I rename it with a war
extension?
3. Am I going down the wrong road with binary deployments? Should I learn maven and approach this as a build-on-demand deployment?
This is a complicated question. It appears that RH docs frame deploying a JVM app to Openshift in JBoss terms. This is not technically necessary, but both Openshift and JBoss are RH products so there is a natural shared audience. For the purposes of this project are you using or do you need to use JBoss with Openshift, or are you able to use Openshift without JBoss?
I’m a noob at java app deployments so take this with a grain of salt: I don’t believe that I have any restrictions on deployment. I don’t need to use jboss/wildfly. I’ve successfully done this following these directions: https://github.com/openshift-evangelists/openshift-cookbook/issues/1 However, that uses the redhat specific redhat-openjdk18-openshift image which is not available (to my knowledge) or at least not deployed in our corporate openshift “origin” environment.
For the previous example, I used lein ring uberjar
yup, got it. am in transit so will respond more fully later but the short version is that an "uberjar" can be run with a command line of java -jar uberjar.jar, so if you can create a docker container image with that file and that start command, openshift will be able to run the image.
hmm, sounds like I need to get into creating my own container image. That’s where I’m wondering if I’m taking the wrong approach and should switch over to git/source deployment and let openshift build for me.
Yes, the goal is a container image, and it seems like using the oc build stuff with the OpenJDK templates is the right way to start. However, it looks like you will need to feed an uberjar to oc build. The builders it seems to have don't know how to take clj source from git and turn that into a jar artifact. So using
lein ring uberjar
should produce that .jar file for you, which you can then do oc startbuild appname --from-file file.jar
to produce a deployable image.
That said, it should be noted that producing the jar locally doesn't give you any provenance in the container image- unless you are exceptionally diligent one wouldn't be able to trace what's in the image to a particular commit in the clj repo.Does lein do clean, ring uberwar
in fact produce a “war”? The produced file is named target/server.jar
. I’m following these directions and trying to use the file as a war file but getting errors on the wildfly console.
http://www.mastertheboss.com/soa-cloud/docker/deploying-applications-on-your-docker-wildfly-image
Those steps should work. It has to produce a jar of the application first, then include that jar in the war. The war I don't believe is written to the root of target, there should be something else there, maybe an uberjar directory?
➜ myapi lein do clean, ring uberwar
Created /Users/dreno200/Documents/dev/projects/myapi/target/server.jar
➜ myapi ls -R |grep -i war
➜ myapi
Not seeing the war file anywhere.
running this, I see differences on server.jar
depending on having used uberjar/uberwar: jar tvf target/server.jar
It seems that server.jar
is the default output regardless of creating a jar or war:
➜ myapi lein do clean, ring uberwar mywarfile.war
Created /Users/dreno200/Documents/dev/projects/myapi/target/mywarfile.war
➜ myapi
Is the name server.jar used anywhere in project.clj? The default naming should include a name and version, so I suspect the name is being overridden in project configuration.
default project file plus :port 8080
:
(defproject myapi "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.8.0"]
[metosin/compojure-api "1.1.11"]]
:ring {:handler myapi.handler/app :port 8080}
:uberjar-name "server.jar"
:profiles {:dev {:dependencies [[javax.servlet/javax.servlet-api "3.1.0"]]
:plugins [[lein-ring "0.12.0"]]}})
Ah, there tis- :uberjar-name. Try removing that key-val pair.
now it creates target/myapi-0.1.0-SNAPSHOT-standalone.war
. I don’t think anything will change for me though, I copy this into my wildfly directory and see this on the console:
17:22:27,394 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0001: Content added at location /opt/jboss/wildfly/standalone/data/content/b9/86413477a47e000b053e6c301f39292460d4cd/content
17:22:27,401 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "myapi-0.1.0-SNAPSHOT-standalone.war" (runtime-name: "myapi-0.1.0-SNAPSHOT-standalone.war")
17:22:38,210 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 77) WFLYUT0021: Registered web context: '/myapi-0.1.0-SNAPSHOT-standalone' for server 'default-server'
17:22:38,224 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "myapi-0.1.0-SNAPSHOT-standalone.war" (runtime-name : "myapi-0.1.0-SNAPSHOT-standalone.war")
Looks good but I still only see the “welcome to wildfly” message on
seems to be getting deployed, I just don’t get any effective web page from it.
thanks for your help on this! I’m a total noob with jar/war deployment. Just trying to ensure that I can actually deploy this somehow before I dive too much into it.
Sure thing- so the log line "...Registered web context: /myapi-0.1.0-SNAPSHOT-standalone" suggests that wildfly will only route requests to that prefix to the deployed app. Try that path from a browser. That's a pretty common pattern for web app containers like wildfly (where the term "container" is completely unrelated to the docker/kubernetes/openshift use of the term)- the container is the host for a number of web applications, and has to be told how to route requests to each. It will use the application/artifact name by default, and configuration can be provided to give it an alternative.
ahh, ok, now I get something but it’s not good. Lots of errors starting with this:
17:39:24,373 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to //myapi-0.1.0-SNAPSHOT-standalone: java.lang.NullPointerException: Response map is nil
at ring.util.servlet$update_servlet_response.invokeStatic(servlet.clj:99)
at ring.util.servlet$update_servlet_response.invoke(servlet.clj:90)
at ring.util.servlet$update_servlet_response.invokeStatic(servlet.clj:94)
at ring.util.servlet$update_servlet_response.invoke(servlet.clj:90)
at ring.util.servlet$make_blocking_service_method$fn__12852.invoke(servlet.clj:113)
at myapi.servlet$_service.invokeStatic(servlet.clj:1)
at myapi.servlet$_service.invoke(servlet.clj:1)
at myapi.servlet.service(Unknown Source)
and many more lines
So that means- the function "app" in the namespace "myapi.handler" is returning nil, rather than returning a map that has :status :headers and :body keys
btw, I renamed the war to ROOT.war
(which I’ve seen somewhere else) and now it responds without a path, still errors
going DM so I can paste a snippet…
Hi there! What would be the best way to write integration tests to a rest api using ring? Do you guys have any examples or resources to suggest?
@caicorre Not sure exactly what you mean by “integration tests”. Are you already using https://github.com/ring-clojure/ring-mock and looking for something more?
That’s exactly it. Thanks!!!
i'm just curious about something. i think this REPL driven development is going to super cool and fun. but as i'm going along in basic tutorials and try things out like "eval-last-sexp" and stuff a lot of times it just says something like "nil." As I learn more about programming is that like a key part of developing programs? I'm not sure what it is actually telling me about the function. i assume i'm just not far enough along but I was just curious and wanted to chat.
an early example was something like this: (defn train [] (println "choo choo!")) and so i just say evaluate expression in my good ole spacemacs. It just says => nil. Now this is a comically trivially function but i figured the repl driven evaluation would be telling me what the function actually does. when i do send it to the repl it does show me it prints out "choo choo" and also nil.