This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-22
Channels
- # announcements (18)
- # babashka (9)
- # beginners (22)
- # biff (2)
- # calva (17)
- # clj-kondo (5)
- # clojure (9)
- # clojure-europe (25)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (7)
- # clojuredesign-podcast (6)
- # clojurescript (61)
- # cursive (11)
- # data-science (1)
- # datahike (3)
- # datomic (2)
- # humbleui (2)
- # hyperfiddle (7)
- # jobs (1)
- # jobs-discuss (4)
- # joyride (1)
- # overtone (7)
- # re-frame (2)
- # reitit (9)
- # releases (2)
- # remote-jobs (8)
- # scittle (1)
- # shadow-cljs (48)
- # squint (8)
I start jar in Clojure use sh
like this:
(clojure.java.shell/sh "java" "-jar" "app.jar")
but sh
not return anything, It's blocked. How can I get this process'id and kill it. My os is windowsIf it's a mystery why the Clojure app does not shut down, then make sure it terminates any Java threads that it starts, and see https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/shutdown-agents
I'm trying to deploy a server on http://fly.io, but fly keeps failing to connect to the machine because the server hasn't started listening on the specified port. Has anyone ever faced this issue before?
Most PaaS services expect a 30 second startup time, which seems pretty reasonable to me. I would check the service is running on the right port number, usually assign by the platform. I log the port number on server startup to check it's what the PaaS is trying to listen upon (usually a port env var)
The port is correct at least. I have tried extending the grace period/intervals for the healthcheck, but I still can't access it. My logs usually look like this:
2024-01-21T18:48:09Z proxy[148ed195c93678] sin [info]machine started in 519.762869ms
2024-01-21T18:48:15Z proxy[148ed195c93678] sin [info]waiting for machine to be reachable on 0.0.0.0:8080 (waited 5.292465366s so far)
2024-01-21T18:48:18Z proxy[148ed195c93678] sin [error]failed to connect to machine: gave up after 15 attempts (in 8.270759979s)
2024-01-21T18:48:18Z proxy[148ed195c93678] sin [error]instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers
often print the address they are listening on)
2024-01-21T18:48:21Z app[148ed195c93678] sin [info]2024-01-21 18:48:21,997 [main] INFO migratus.core: Starting migrations
2024-01-21T18:48:24Z app[148ed195c93678] sin [info]2024-01-21 18:48:24,934 [main] INFO migratus.core: Ending migrations
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,260 [main] INFO rm.config: Server started on port: 8080
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,365 [main] INFO org.eclipse.jetty.server.Server: jetty-11.0.18; built: 2023-10-27T02:14:36.036Z; git: 5a9a771a9fbcb9d36993630850f612581b78c
13f; jvm 21.0.1+12-LTS
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,492 [main] INFO org.eclipse.jetty.server.handler.ContextHandler: Started o.e.j.s.ServletContextHandler@6cd31e5f{/,null,AVAILABLE}
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,504 [main] INFO org.eclipse.jetty.server.AbstractConnector: Started ServerConnector@44b99f09{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,509 [main] INFO org.eclipse.jetty.server.Server: Started Server@1737acc0{STARTING}[11.0.18,sto=0] @15717ms
Are you seeing continued failures in the logs after jetty starts? What does your fly.toml look like? Or at least the services or http_service section and any checks.
No, after jetty starts there's no additional logs/errors. Here's my fly.toml:
app = "rmrt1n"
primary_region = "sin"
[build]
[env]
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
[[http_service.checks]]
interval = "30s"
timeout = "5s"
grace_period = "120s"
method = "get"
path = "/"
[[vm]]
cpu_kind = "shared"
cpus = 1
memory_mb = 1024
[mounts]
source = "rmrt1n_storage"
destination = "/data"
I am going through "Clojure for the Brave and True" and there is this code:
(defn criticize-code
[criticism code]
(println
criticism (quote code)))`
I know the difference is that macros and functions is that macros evaluate at compile time, but I thought the other difference was that macros don't evaluate forms, and functions have to. But this function doesn't evaluate code! So does that mean that my belief that functions always evaluate forms is incorrect?
A function's arguments are evaulated before being passed to the function. This function, which syntax-quotes its return value, doesn't necessarily evaluate the return value (because it's quoted)
unlike function macros does not evaluate arguments but they both evaluate its body during definition
backtick is a mark for compiler that following form should be treated as quoted code template allowing within it additional syntax like ~
and ~@
I understand, I just thought that functions always evaluate the forms that are passed to them.
that is correct
if we make a macro with the same body and macroexpand it, we can see that unevaluted forms go to the macro:
; note that 1 and 2 got added here, and 3 was passed to the function
(criticize-code "hi" (+ 1 2))
=> (clojure.core/println "hi" (quote 3))
; here, the form (+ 1 2) got passed to the macro (as opposed to the result of (+ 1 2))
(macroexpand '(criticize-code-m "hi" (+ 1 2)))
=> (clojure.core/println "hi" (quote (+ 1 2)))
Oh, so my reading of that chapter was correct. Okay, thank you so much Bob and delaguardo.
Arguments to functions are evaluated before functions are applied, functions don't evaluate
Macros get the arguments as unevaluated forms, but the call to the macro is replaced with whatever the result of evaluating the macro is, which in this case is a list (which evaluates as a function call) where the first element is the symbol clojure.core/println, the second element is the form that was passed to the macro, and the third element is the form that was passed to the macro wrapped in a layer of quoting
Understanding quote (`'`), syntax-quote (```), unquote (`~`) and also gensym (`<symbol>#`) can be helpful; all introduced with good, brief code examples at http://Clojure.org: https://clojure.org/guides/weird_characters#syntax_quote