Fork me on GitHub
#clojure
<
2019-11-29
>
orestis08:11:49

Anyone with experience with https://github.com/sunng87/diehard ? I have a "process" (single thread actually) that pulls data from SQS. In the event that SQS or network falls over transiently, I'd like to back off and retry a little bit later. A circuit breaker seems like a useful abstraction...

cjohansen10:11:34

When using reify with a Java interface, is there some way to store state on this, or do I need to keep state eg in a separate atom?

vemv12:11:56

fwiw, the following pattern works:

(let [a (atom nil)]
  (reify ...))
i.e. the atom is not very disjointed from the reify. This is documented: ...and can refer to the surrounding local scope

cjohansen12:11:48

yeah, this is what I did. just felt a little awkward

vemv12:11:24

at the same time, imagine rich had to choose (and impose!) a specific state model implicit in reify bodies... e.g. built-in atom? or built-in Java volatiles? tough choice

cjohansen13:11:30

yup, probably makes sense

lsenjov11:11:34

Are there any tutorials/details on how to deploy a JAR/WAR to an Azure app service? (I can't use another cloud provider due to client limitations) Deploying WARs on Tomcat keeps stopping me as there's no services folder under META-INF. If that's manually added to the META-INF I get a lot of truncated class errors or ClassNotFoundExceptions, despite them appearing in the extracted WAR Deploying a JAR seems to just die and I can't figure out why yet The couple of things written on the subject are either "just host a VM" or are around using the Azure webapp maven plugin, which I don't understand how to interface with Lein/whatever other loader I need to use Any help is appreciated

vemv12:11:02

Given a coordinate vector such as '[lambdaisland/deep-diff "0.0-29"] , is there a handy function that will print its description? Ideally fetching it from ~/.m2 , for speed

Azrea13:11:10

Would you expect this to work?

(->> values
     (map async-fn)
     a/merge
     (a/into {})
     a/go)

๐Ÿ‘ 4
facepalm 8
borkdude15:11:04

if I would publish a library with java code that uses clojure.lang.RT and that lib would for example depend on 1.9, will that library be usable in a project which depends on clojure 1.10?

andy.fingerhut15:11:07

In general there is no promise by the Clojure core team that such things will work. They do not consider clojure.lang.RT as part of the public API of Clojure's implementation.

andy.fingerhut15:11:33

In practice, it will often work between two consecutive Clojure versions, but you don't have cause for complaints or bug filing if it doesn't.

Alex Miller (Clojure team)15:11:16

Generally, yes. Calls to RT get embedded into aotโ€™ed code so as a general policy we only ever make additive changes to it (I canโ€™t remember an exception to that in the last 7 yrs at least)

seancorfield16:11:53

@U04V15CAJ Why use clojure.lang.RT when you have https://clojure.github.io/clojure/javadoc/clojure/java/api/Clojure.html which is a public, supported API?

borkdude16:11:54

@U04V70XH6 because I needed the unpublic API to replicate some behavior of Vars, but it turns out I can do it in Clojure itself ๐Ÿ™‚ https://github.com/borkdude/sci/blob/e2a875b6856426d3ced11f11f01266c81406ad49/src/sci/impl/vars.cljc#L145

borkdude16:11:01

so, this question is now obsolete, but still good to know

4
cjohansen21:11:24

I recently asked for consuming server-sent events from Clojure. There was little help to find, so now there is this: https://github.com/cjohansen/clj-event-source

noisesmith21:11:25

this library calls join on a thread inside a go block, which is a very bad thing

noisesmith21:11:33

you could fix it by calling thread instead of go at the end of connect, otherwise this code can deadlock all of core.async just by having enough requests in flight

noisesmith21:11:09

in fact, you don't even need thread, you could just use future, as that body doesn't need any core.async features

cjohansen21:11:23

cool, thanks

cjohansen21:11:44

that's pretty damn fast code review ๐Ÿ™‚

noisesmith21:11:47

I'm debating whether I'm too lazy to create an issue on htis lib haha

cjohansen21:11:00

It's OK, I'll just fix it immediately

noisesmith21:11:09

it's easy because everybody predictably makes this mistake

noisesmith21:11:33

ahh! I didn't realize it was your code until just now

cjohansen21:11:40

it is ๐Ÿ™‚

cjohansen21:11:42

so basically replace go with future, and that's it?

noisesmith21:11:19

right - the gotcha with future (and thread) are that they can leave failures in limbo, but the try catch you already have addresses this

cjohansen21:11:22

I have very limited experience with Java futures ๐Ÿ˜•

cjohansen21:11:50

I did test it. It's basically there to catch connection problems

noisesmith21:11:18

the future macro takes arbitrary code in an implicit do, and ensures that it runs in a new thread with clojure bindings conveyed for dynamic vars

noisesmith21:11:46

right - this code works great for < N connections, then with N connections in flight all of core.async stops

noisesmith21:11:20

but future (and async/thread) uses a cached expandable pool, which adresses this issue

cjohansen21:11:59

thanks alot for the quick and detailed feedback!

noisesmith21:11:49

and a minor style thing: instead of

(try (.join res) (close! port) (catch ... (close! port)))
you can have
(try (.join res) (catch ...) (finally (close! port)))

cjohansen21:11:26

ah, of course

noisesmith21:11:47

unless the catch has to act on errors in (close! port) - but in that case it shouldn't be trying to do it again, right?

cjohansen21:11:43

no, the close here is just a best effort really

cjohansen21:11:12

if you already closed it, you're doing some strange stuff, and if it's closed, it's closed

cjohansen21:11:28

alright, new version on Clojars and github, thanks again ๐Ÿ™‚

cjohansen21:11:38

it uses the http://java.net.http stuff from Java 11

borkdude21:11:01

I want to add two methods to a deftype, e.g.:

(defprotocol IBox
  (setVal [_ _])
  (getVal [_]))
But I want to keep IBox private, is that possible?

borkdude22:11:16

yes, I'm already having that. I guess that's enough

andy.fingerhut22:11:15

I do not know if it works for anything other than def and defn, but did you try adding ^:private metadata to the name?

gerred22:11:06

โ— Does someone happen to have a copy of Enter Integrant by @weavejester? It looks like the company hosting the video linked in the Integrant repo has gone under administration: https://skillsmatter.com/skillscasts/9820-enter-integrant - sad, and it looks like there's replacement talks out there that aren't this talk (including by @weavejester), but it would nice to preserve it, though I don't know the IP rights around that video.

dominicm22:11:32

They're on vimeo, but they were private

seancorfield22:11:07

The loss of SkillsMatter has meant the loss of a lot of Clojure content online, unfortunately ๐Ÿ˜ž