This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-29
Channels
- # announcements (8)
- # aws (34)
- # beginners (92)
- # calva (19)
- # capetown (1)
- # cider (10)
- # cljs-dev (7)
- # cljsrn (11)
- # clojars (7)
- # clojure (130)
- # clojure-europe (4)
- # clojure-italy (4)
- # clojure-losangeles (1)
- # clojure-nl (11)
- # clojure-russia (1)
- # clojure-spec (4)
- # clojure-uk (64)
- # clojurescript (51)
- # cursive (9)
- # data-science (6)
- # datomic (29)
- # emacs (3)
- # figwheel-main (14)
- # fulcro (4)
- # graphql (3)
- # jackdaw (2)
- # jobs (4)
- # kaocha (17)
- # leiningen (3)
- # luminus (1)
- # off-topic (46)
- # pedestal (6)
- # portkey (2)
- # re-frame (6)
- # reagent (1)
- # reitit (9)
- # shadow-cljs (9)
- # sql (10)
- # yada (6)
does anyone have an example of a system (a la component/integrant/mount) whose resources have to be stopped in order?
@lilactown hypothetical: using zookeeper for service discovery / leader election, you need to withdraw from any roles your instance took on, and do any zk bookkeeping, before shutting down your zookeeper component that manages your connection to the service
(of course if it's properly designed the failure case should handle that already, but you might be able to do something simpler if a node explicitly and gracefully leaves)
nice! does that match what I’m talking about though? I mean that if component A
depends on B
:
start:
A -> B
B
must be started before A
. I’m wondering how often it’s important that B
also be stopped before A
in this case, are you saying that you have two components (e.g. one for service discovery, one for the component itself)?
oh! - I thought you meant "in order" as in "opposite from starting order" which is how it's done...
I guess? I actually haven’t used component in a while and it never mattered in my cases.
@lilactown in my example the hypothetical service isn't the only usage of zookeeper, so the zk component is shared by 2 or more components
sometimes shutdown of B requires usage of A
OK, so you’d probably want to withdraw before you shut down the rest of your system so you don’t get incoming requests during your shutdown
if there's any tidying up needed - of course we usually try to build things so worst case we don't leave state dangling
another hypothetical: there's a lock file on a filesystem where two programs run (eg. an editor), you'd want to shut down the part of your app that wants to write the file before shutting down the part that does file locking and directory watching
and on startup you want to open the part that watches and locks files before the part that wants to write them
often we avoid this by not splitting concerns, but in a focused enough file management oriented app, I can imagine separate components
so you can stop the app, and leave things in a good state were you can start it again without restarting the jvm
oh, and a much more common / obvious example than the others: imagine if your http server was still running and handling requests, but your db access handler was shutting down
I think that’s the example I’ve been running with so far, and I don’t really care that much
I guess a spurious 500 error isn't hard to handle
so e.g. the file locking example was great, I hadn’t thought about things like that
Hi everyone, I'm new to clojure and clojure.test so can anyone tell me how to write test cases for any project.
You'll find the #beginners channel very helpful -- people there have opted in to helping folks who are new to Clojure @vikram
Thanks @U04V70XH6 for the suggestion.
@vikram you can start here https://clojure.github.io/clojure/clojure.test-api.html
Hey @unni, Its like I have read that link and I've created a project in which I wrote a simple test and after running cider and using C-c C-t p, it is saying that "Running test in all namespaces" in minibuffer but it is not showing the output.
(ns testcase.core (:require [clojure.test :refer :all] [ring.adapter.jetty :as jetty] [ring.middleware.reload :refer [wrap-reload]] [compojure.core :refer [defroutes GET]] [compojure.route :refer [not-found resources]] )) (deftest addition (is (= 3 (+ 1 1))) (is (= 4 (+ 2 2)))) (defn -main "A simple project to runtest case" [port-number] (jetty/run-jetty (wrap-reload #'addition) {:port (Integer. port-number)})
@vikram that is happening because you have this in src namespace and not test namespace from the looks of things.
Shouldn't https://github.com/edn-format/edn/wiki/Implementations also mention Clojure's built-in https://clojure.github.io/clojure/clojure.edn-api.html? For anyone trying to use EDN format from Clojure, it'd be really nice to get a pointer which one should use. According to https://groups.google.com/forum/#!topic/clojure/d61ImK2VCag the built-in is just fine.
I have a repl with refs to datomic entities defined. Periodically I wish to refresh these to include recent novelty. A macro approach could look like
(defmacro refresh-datomic-entity-as-macro
"redefine ent-sym to latest version of entity"
[ent-sym datomic-conn]
`(def ~ent-sym
(d/entity (d/db ~datomic-conn) ~(:db/id (deref (resolve ent-sym))))))
but realised that I could alternatively write the function
(defn refresh-datomic-entity-as-fn
[ent-var datomic-conn]
(.alterRoot ent-var (fn [e] (d/entity (d/db datomic-conn) (:db/id e))) '()))
normally I would always choose a function over a macro
but perhaps not if that required the interop call to clojure.lang.Var/alterRoot
How would you choose between them??
are they equivalently awful?:ahem: hadn't spotted that function
thankyou
haha I've never written a macro that I've ended up keeping
I didn't know .alterRoot
existed so that's TIL 🙂
I just want to profess the ridiculous feeling of joy and power I have when using Clojure. 200 lines to achieve what in my other proficient languages would be 2,000. I know it’s not a real measuring stick, but every once and awhile I come up for fresh air and look at some of the stuff people are doing, and realize how much more approachable Clojure code bases are. Thank you Rich/Stu/Alex/et. al.!



I could probably write a long post about it 😄 one of bigger reasons, honestly, was that we started rewriting our systems at work last year and needed something to standardize on. Clojure was just a better bet back then. Still is
I came from an OCaml-ish language (F#) to Clojure and wrote something about the transition here https://blog.taylorwood.io/2017/09/15/year-behind.html I also feel ridiculously empowered when writing Clojure. I did C#/Java/C++ for ~15 years before learning functional programming FWIW
Blue collar probably doesn’t translate across cultures/regions with any precision. I’d be interested in the longer motivation? 🙂
@UCW3QKWKT I interpret that as the daily work of an average programmer
@lilactown Absolutely love the, "blue collar" programming language metaphor, while I understand the response about it not translating it made deep and intuitive sense to me immediately and will now be stolen. Bravo.
I've probably taken about a dozen languages to production -- and I've learned another dozen while doing that (and I came out of university fluent in about another dozen before that) -- and Clojure feels, for me, the most fun and productive of any language I've ever used.
it already happened a few times that we change something, everything works in the REPL and running tests, but then eventually you run the Uberjar generated and it blows up
is normally related to silly things like slurp
of files not in resources
, and similar, but it would be nice to find out earlier on
one way for example could be to run the uberjar generated for a few seconds and do an HTTP call to see if it started up correctly, has anyone done something like that?
it’s always useful to test things in a release-like environment before deploying. We use docker at work to do that
we also use docker
so I can run something on the docker image
was just wondering how to run for example jetty for a few seconds until it's up to try to do a HTTP call
and we also have health checks, however when there are these issues marathon can't even deploy the changes, and it just loops forever
just wanted to know if I was the only one with this problem, and others solved it
Weird. I told my friend about a cult I joined and he told me it sounded like being a clojure developer.
writing Clojure with Emacs is a double cult then 😄
All the best cults write clojure.
Hi, has anyone used com.taoensso/carmine with Redisgraph? I can successfully (car/PING)
my running Redisgraph Docker container, and I see four graph commands listed when I run (wcar* (car/command))
. But, when I try e.g. (wcar* (car/graph.QUERY "social" "CREATE (:person {name: 'roi', age: 33, gender: 'male', status: 'married'})"))
, it tells me No such var: car/graph.QUERY
. Haven’t used carmine or Redis much previously, but wanted to have a go.
👋 any known lib/utils that given a string: 1. tell me if it's a valid uri 2. tell me if that uri refers to an image of any kind ❓
maybe a combination of https://github.com/cemerick/url for 1 and https://github.com/michaelklishin/pantomime for 2 :thinking_face:
You can use the URI class constructor in the JDK to check for validity. It will throw an exception if it invalid (assuming you mean structurally valid, as opposed to the resource it points to actually existing).
Number 2 sounds hard though. http://myserver.com/pictures/myface is a valid URI. You'd have to do a HEAD at minimum to see what's there though.
https://github.com/michaelklishin/pantomime#detecting-mime-type looks pretty good. planning to test it out on some edge cases
or maybe it's equality checks - but what I definitely remember is strange unexpected network interactions
@noisesmith do you know where that’s documented? I knew that was the case for java.net.InetAddress
, but URI
is surprising :S
@nwjsmith thanks for making me double check: URL has this behavior, URI is safe(!) > Equality, hashing, and comparison are defined strictly in terms of the character content of the instance. In other words, a URI instance is little more than a structured string that supports the syntactic, scheme-independent operations of comparison, normalization, resolution, and relativization. https://docs.oracle.com/javase/7/docs/api/java/net/URI.html
I is only four letters away from L, and looks very similar in most fonts, which is my excuse for my faulty memory
Haven’t even sent in the money yet, and Riches are already ensuing.
shut up and take my money
Is there a caching system where if the result is not available, then the old one is used until it is? Eg for a variable time api
Core.cache doesn't seem to have something like this. I feel like I could try something with a futures and deref, but state gets a little complicated, and utilizing someone else's state management seems reasonable.
if the result is “not available”, then how can there be an “old one”?
sounds like maybe what you want is a map + a way to trigger a background refresh ?
I’m not sure I would call that a cache
Is there a plan of releasing the new version of tools.deps.alpha with ’add-lib function? It’s needed to add hotload-dependency functionality to clj-refactor., because otherwise I’m unable to add the tools.deps.alpha using it’s hash.
it needs some more work before it gets added, which is likely not going to happen soon
so, no there is no plan currently
May I please take the code from add-lib branch and create a package out of it? At least for some time until the feature lands to tools.deps.alpha
It’s open source… just retain the license and copyright
that is, yes :)
@alexmiller you're right, I think an atom & a thread is probably good here. My only slight problem is eviction.
core.cache has a protocol. one of the functions is evict
. maybe you could look at the LRU there and modify it so that evict did not evict but refresh?
@dominicm I have exactly this problem and solved it with an atom with a map of futures. I need a value for every user of the system. Each user has a future, either running or ready. I do a background refresh, so I don’t throw away the future that’s already done while the new one is running.
The problem is that futures don’t have a way to say: on-ready, put yourself in this map and swap out the other future. So I’m dereferencing it in the background, with a timeout. When done (or the timeout expires), I swap the old value.
> if the result is not available, then the old one is used until it is i seem to build or want this in every lang or system i work on 😂
you could give the future the atom and then have it do the swap?
I don’t know the Guava lib well enough to know off-hand if this is covered, but it has a ton of cache variants and the code is very high quality
@alexmiller then I would need a way for the future to refer to itself
it’s waiting for something - when it’s done waiting, do the work
because I store the futures, not the resulting values. if there’s already a future running (and not cancelled), I wait for that one. I could store the resulting values separately in another atom of course, but I still need the state of those futures.
@borkdude a future is effectively a Thread plus try/catch/finally that delivers to a promise
you could make a new version that lets the code in that Thread access the promise directly
of course a clojure future also does some special var binding boilerplate, but it's a relatively small chunk of code
@noisesmith so instead of storing the futures, I would store the promises?
yeah, which I think have the semantics you want - they are deliver-once, and you can tell if they've been delivered too
maybe you want a pair of promises - one for the thread itself (has this work started) and another for the result (has it completed / what did it return)
I'm a huge fan of delay and promise, you could also use atoms for what they do, but they have the extra guarantee that they never mutate once realized, a one time switch