Fork me on GitHub
#beginners
<
2024-01-22
>
quan xing06:01:57

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 windows

quan xing07:01:32

Thanks. It's working.

phill11:01:00

If 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

Ryan Martin09:01:13

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?

practicalli-johnny13:01:22

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)

Ryan Martin13:01:04

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

chucklehead16:01:32

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.

Ryan Martin05:01:51

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"

yagkasha15:01:41

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?

Bob B15:01:33

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)

delaguardo15:01:34

unlike function macros does not evaluate arguments but they both evaluate its body during definition

delaguardo15:01:24

backtick is a mark for compiler that following form should be treated as quoted code template allowing within it additional syntax like ~ and ~@

yagkasha15:01:01

I understand, I just thought that functions always evaluate the forms that are passed to them.

delaguardo15:01:17

that is correct

Bob B15:01:02

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)))

clj 1
yagkasha15:01:13

Oh, so my reading of that chapter was correct. Okay, thank you so much Bob and delaguardo.

hiredman15:01:22

Arguments to functions are evaluated before functions are applied, functions don't evaluate

yagkasha15:01:45

Ah, okay. Thank you for that clarification.

hiredman15:01:55

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

hiredman15:01:35

When a quoted form is evaluated it just removes a layer of quoting

silian06:01:31

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