clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
kah0ona 2021-03-09T08:37:37.342100Z

(future
    (try
      (println "inside future body")
      (assert false) ;;
      (catch Exception e
        (println "error" (.getMessage e))))) ;; no error printed

  (try ;; not in a future, but just normal
    (println "inside future body")
    (assert false) ;;
    (catch Exception e
      (println "error" (.getMessage e)))) ;; error printed

  (future
    (try
      (println "inside future body")
      (throw (ex-info "throwing" {}))
      (catch Exception e
        (println "error" (.getMessage e))))) ;; error printed

kah0ona 2021-03-09T08:38:12.342800Z

the top one doesn’t go to the catch clause

kah0ona 2021-03-09T08:38:18.343Z

but the others do

kah0ona 2021-03-09T08:38:33.343300Z

but why?

flowthing 2021-03-09T08:46:12.344Z

user=> (assert false)
Execution error (AssertionError) at user/eval17874 (REPL:1).
Assert failed: false
user=> (instance? Exception *e)
false
user=> (instance? Throwable *e)
true

flowthing 2021-03-09T08:47:01.344200Z

That is, assert throws AssertionError if it fails. AssertionError is not an Exception, but it is a Throwable.

👆 1
flowthing 2021-03-09T09:45:30.344500Z

See also https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions

dangercoder 2021-03-09T10:40:01.347900Z

How do you handle interopt with Java's Functional Interfaces? Right now it's Reify for me and some nice to have functions & macros. I've looked into libraries such as https://github.com/athos/power-dot

vemv 2021-03-09T10:56:36.348200Z

I use reify - it's simple, transparent and flawless. The only problem IMO is discovery (what interfaces/methods should one implement). Extending https://github.com/alexander-yakushev/compliment/ might help if you use cider-nrepl

vemv 2021-03-09T11:26:15.348800Z

clj-refactor.el's cljr-add-stubs also helps. I discovered a minor bug in it though https://github.com/clojure-emacs/clj-refactor.el/issues/479 (discovered while doing Functional stuff)

aratare 2021-03-09T11:54:52.349500Z

Hi there. Is there a way to restart the agent thread pool after shutdown-agents has been called?

dangercoder 2021-03-09T11:57:01.349600Z

cool, thanks for the insight @vemv 🙂

alexmiller 2021-03-09T13:42:44.350700Z

I’m very curious what your use case is leading you to ask - the core team has been looking at this

alexmiller 2021-03-09T13:43:23.351100Z

cc @fogus

alexmiller 2021-03-09T13:43:41.351400Z

No

valerauko 2021-03-09T14:39:32.351500Z

my experience: https://blog.valerauko.net/2020/11/23/clojure-and-java-functional-interfaces/

emccue 2021-03-09T15:02:40.352500Z

@rextruong technically you can set the agent executors to something custom that could support restart

2021-03-09T15:03:40.353100Z

Can we set the thread pool size used by future?

alexmiller 2021-03-09T15:04:44.353900Z

those methods @emccue linked can be used to customize the executors

emccue 2021-03-09T15:04:50.354200Z

That uses clojure.lang.Agent/soloExecutor

emccue 2021-03-09T15:05:10.354800Z

which is what set-agent-send-off-executor! changes

alexmiller 2021-03-09T15:05:30.355100Z

that said, there is no thread pool size for that pool - because it can do IO, you can lock up the runtime if you constrain it

2021-03-09T15:06:08.355500Z

Yup. That’s why I want to make the threadpool a little bit larger.

alexmiller 2021-03-09T15:06:16.355700Z

there is no thread pool size

alexmiller 2021-03-09T15:06:24.355900Z

it adds threads as needed

emccue 2021-03-09T15:08:25.356700Z

volatile public static ExecutorService pooledExecutor =
	Executors.newFixedThreadPool(2 + Runtime.getRuntime().availableProcessors(), 
		createThreadFactory("clojure-agent-send-pool-%d", sendThreadPoolCounter));

volatile public static ExecutorService soloExecutor = Executors.newCachedThreadPool(
	createThreadFactory("clojure-agent-send-off-pool-%d", sendOffThreadPoolCounter));

2021-03-09T15:10:22.357700Z

Thanks. Was checking that too.

emccue 2021-03-09T15:11:58.358400Z

and none of this is there in the docs of future

emccue 2021-03-09T15:12:00.358700Z

Takes a body of expressions and yields a future object that will
invoke the body in another thread, and will cache the result and
return it on all subsequent calls to deref/@. If the computation has
not yet finished, calls to deref/@ will block, unless the variant of
deref with timeout is used. See also - realized?.

emccue 2021-03-09T15:12:35.359500Z

but it is alluded to in a comment in one of the community examples

emccue 2021-03-09T15:12:59.359800Z

;; Note: If you leave out the call to (shutdown-agents), the program
;; will on most (all?) OS/JVM combinations "hang" for 1 minute before
;; the process exits.  It is waiting for a thread created by the
;; future call to be shut down.  shutdown-agents will shut them down
;; immediately, or (System/exit <exit-status>) will exit immediately
;; without waiting for them to shut down.

alexmiller 2021-03-09T15:16:17.360200Z

if you want to file a docstring request, please log a question at https://ask.clojure.org

James Carr 2021-03-09T15:19:11.361600Z

What is a really good fullstack demo clojure application? Looking for something I can just clone and run docker-compose up, play around with some metric tracking that interests me on the devops side of the house

2021-03-10T14:12:42.412Z

http://www.luminusweb.com is a good start

borkdude 2021-03-09T15:19:48.362Z

Maybe juxt/edge?

James Carr 2021-03-09T15:24:12.362600Z

https://github.com/juxt/edge?

James Carr 2021-03-09T15:26:03.363200Z

Looks close... was hoping to find something working with a database like postgresql that I could just run docker-compose up on

p-himik 2021-03-09T15:31:05.363500Z

This looks like a good fit: https://github.com/tbsschroeder/clojure-webshop-app

p-himik 2021-03-09T15:31:33.363700Z

Not sure about the "really good" part - I've never seen it before. Just something I was able to find quickly.

2021-03-09T15:44:25.368Z

Hey all, do you have a favorite process manager for your apps? I've got multiple Clojure/ClojureScript apps running on a single VM, and I'm trying to find a good way to wrangle them. Not only for things like automatically restarting apps on server reboot, but also for development (streaming logs for debugging, stopping the app, restarting the app, etc.) I've enjoyed using Supervisor a lot (http://supervisord.org/), but I'm finding that there are logs coming out of my apps which don't end up in either the stdout or stderr logfiles. It's got such a nice CLI, but if I'm missing errors or failed ShadowCLJS compilations, then it's hurting me more than it's helping me. Anyway, any recommendations?

ghadi 2021-03-09T15:55:54.368800Z

systemd if you're not going to go the container route

ghadi 2021-03-09T15:56:34.369400Z

Is this is for a dev setup then maybe something different

2021-03-09T16:04:45.375500Z

What I'm trying to achieve is a unified prod/dev kind of thing. I want to develop in the same environment that my production app will run in. I've got everything in a Vagrant VM, so I've got the environment part of it figured out, but what I'd like is something that will make developing on the VM as "easy" as developing directly on my local. If I was developing on my local for example, I'd probably open up a few different terminal windows and invoke clj -M:alias or whatever the startup command is for each app. My dream VM version of that is to have a little CLI that can invoke all of the startup commands, can foreground/background the apps easily, and can still give me that same direct access to streaming logs. Supervisor can almost do all that, but logging everything from one app to one streaming output doesn't seem to be possible, at least as far as I can see.

2021-03-09T16:05:21.375600Z

I do like systemd for automatically starting processes and stuff like that, but it would only solve part of my problem.

lukasz 2021-03-09T16:12:47.375800Z

To be honest, I'd go with Docker and Docker compose for single-machine, multi-app deployment. Your dev environment and production will always be different

schmee 2021-03-09T16:40:09.378600Z

there’s also https://github.com/ajoberstar/ike.cljj/

alexmiller 2021-03-09T16:44:12.380200Z

I'm familiar with all these, what I'm looking for is: what problems are you having in your code base where you reach for these?

alexmiller 2021-03-09T16:44:36.380400Z

"I wanted to do X but I couldn't or it was cumbersome... "

lilactown 2021-03-09T16:49:03.384300Z

I'm once again running into the wall that is my ignorance of JVM multithreaded constructs. looking for advice: I working on a bit of CLJC code that schedules a task to be run in some way that doesn't hog the current thread. It sounds like in the JVM nomenclature this could be easily handled by an ExecutorService?

Jakub Holý 2021-03-09T16:49:08.384500Z

Any good ideas for extracting all calls to (log/warn ...) from .cljc files? I thought about simply using clojure.edn/read and then prewalk the data but it cannot be read because of #?(..) Is there some cljc aware reader? Thanks!

Jakub Holý 2021-03-09T16:50:48.384600Z

Yes. Or just use (future..) if you don't need to set up a dedicated thread pool and are ok with using the default one...

lilactown 2021-03-09T16:51:34.384800Z

ah, I guess I should have specified that multiple tasks could be queued up at once and I want to process them in some order

lilactown 2021-03-09T16:52:08.385Z

hence the desire for something more than (future ,,,)

lilactown 2021-03-09T16:53:10.385200Z

this might be more than you're looking for, but https://github.com/borkdude/edamame I think fits the bill

lilactown 2021-03-09T16:53:34.385500Z

you can configure it to process reader conditionals

flowthing 2021-03-09T16:54:58.385700Z

clojure.core/read-string also takes :read-cond :allow, but note that it can execute code if *read-eval* is true.

flowthing 2021-03-09T16:55:55.385900Z

I think you can also use https://github.com/jpmonettas/clindex or clj-kondo to find var usages.

Jakub Holý 2021-03-09T16:58:37.386200Z

Thank you!

2021-03-09T17:07:55.386700Z

What would be the benefits of Docker over Vagrant? I'm fairly comfortable in a *nix environment, but pretty new to developing on a VM. After a little research, Vagrant seemed like a good option for my goals. And I do think I've achieved that 1:1 parity between dev and prod to be honest (complete with SSL and everything). I do like the idea of hitting all of my "production problems" early on so I don't have to encounter and solve all of them in the 11th hour before I deploy, but it does seem to add a lot of complication too. I'd be curious to get your perspective though.

lukasz 2021-03-09T17:15:01.387Z

I've used Vagrant at multiple shops as means of standarizing dev environments, and it never looked like production (even before Docker), on top of that developer experience is not so great, especially when it comes to 'edit locally see changes in the VM', that part is always flaky. Of course you can work in the VM directly, and that (IMHO) works great if you accept some trade-offs (performance being the biggest one). Now for production, even if we're talking about a single machine - Docker simplifies this in many ways: you can test and build software locally with the same compose setup, but you get the additional benefit of not tying your application's runtime to the host, and forces you early on to figure things like secrets management, repeatable builds and so on. Sorry for the random thoughts, I'm just speaking from experience of trying to achieve dev-prod parity and never seeing it realized fully (or even in 50%)

schmee 2021-03-09T17:15:40.387200Z

you might be familiar with all these, but @jarvinenemil might not be, and he asked the original question 🙂

alexmiller 2021-03-09T17:57:49.388200Z

oh for sure, thx for dropping them

alexmiller 2021-03-09T17:57:54.388400Z

I am hijacking :)

dangercoder 2021-03-09T18:38:38.388700Z

@alexmiller I asked because the functional interface interopt becomes cubersome due to the proliferation of interfaces that one has to explicitly implement. example in the kafka streams DSL Java

streams
.filter((k, v) -> value.equals("Purple haze, all in my brain"))
.mapValues(value-> value.toUpperCase());
Clojure
(-> streams
    (.filter (reify Predicate
               (test [_ k v]
                 (= "clojure-rocks!" v))))
    (.mapValues (reify ValueMapper
                  (accept [_ v] (clojure.string/upper-case v)))))

Jakub Holý 2021-03-09T18:56:52.389Z

Do tasks support pausing? I guess look at the E.S.api,does it do what you want?

jmckitrick 2021-03-09T19:37:28.390100Z

Are there any current libraries for SFTP? Or does it make sense to just wrap the apache commons functions for SFTP?

vemv 2021-03-09T19:38:31.390200Z

there's tools.reader also with .cljc support

👍 1
lilactown 2021-03-09T19:38:48.390400Z

I don't think so out of the box

lilactown 2021-03-09T19:39:16.390900Z

I'm tempted rn to build my own task running/scheduling machine using core.async but I also really don't want to depend on core.async

borkdude 2021-03-09T19:39:34.391400Z

@jmckitrick I've been using this one for a long time and it hasn't disappointed me https://github.com/miner/clj-ftp

jmckitrick 2021-03-09T19:40:17.392100Z

I saw that, but didn't see sftp support on the home page. Guess I should dig a little deeper?

p-himik 2021-03-09T19:40:32.392200Z

As an alternative to Docker, it might be worth looking into podman. It's almost a drop-in replacement that doesn't require root privileges.

borkdude 2021-03-09T19:41:13.392700Z

hmm, I guess you're right. sorry

jmckitrick 2021-03-09T19:41:31.393Z

Rats. I was hoping you were right.

vemv 2021-03-09T19:43:10.393400Z

The repo is active though so you may have luck requesting that feature. Or maybe simply hacking that .clj file

viesti 2021-03-09T19:43:30.393900Z

maybe https://github.com/clj-commons/clj-ssh

alexmiller 2021-03-09T19:59:00.394200Z

but why are you using streams at all? why not just filter / map in clojure

alexmiller 2021-03-09T19:59:55.394400Z

where are you getting the streams from?

alexmiller 2021-03-09T20:00:02.394600Z

kafka I guess

alexmiller 2021-03-09T20:00:22.394800Z

do you have a link to where you're getting that example?

dangercoder 2021-03-09T20:48:55.395Z

you're correct @alexmiller, it's an example from the official java client kafka streams lib: Simple Clojure example (not mine, but identical to the code that I gave as an example) https://github.com/perkss/clojure-kafka-examples/blob/master/kafka-streams-example/src/kafka_streams_example/core.clj Java example mapValues in the official docs: https://kafka.apache.org/20/documentation/streams/developer-guide/dsl-api.html

dangercoder 2021-03-09T20:50:27.395700Z

If you prefer a gist with 100% identical java/clojure I can fix that

alexmiller 2021-03-09T20:54:18.395900Z

nah

alexmiller 2021-03-09T20:54:23.396100Z

that's helpful, thx

✌️ 1
schmee 2021-03-09T21:14:56.396300Z

@jarvinenemil you’ve probably seen this, but there is also https://github.com/fundingcircle/jackdaw

Ben Sless 2021-03-09T21:15:55.396600Z

core.async already has a running/scheduling machine for tasks - pipelines. They guarantee order maintenance and predetermined parallelism. They're pretty good at their job

Ben Sless 2021-03-09T21:16:40.396800Z

But not suitable for pause-resume

dangercoder 2021-03-09T21:21:59.397100Z

I have seen it, it seems nice but I prefer embracing java-interop

👍 2