Genie Discord forum

Author AvatarWheredNateGo
11/21/2022, 5:09:27 PM

Hi everyone! I'm trying to automatically force compile certain routes when launching a server using bin\repl or bin\server. I've seen the script below but I'm not sure where to put something like this in the directory to have it run correctly. As I understand it, force_compile() would need to run immediately before up(). Any suggestions?

using Genie, Genie.Router, Genie.Requests, Genie.Renderer.Json

route("/foo") do 
  json(:foo => "Foo")

route("/bar") do 
  json(:bar => "Bar")

function force_compile()

  for (name, r) in Router.named_routes()
    Genie.Requests.HTTP.request(r.method, "http://localhost:8000" * tolink(name))

@async force_compile()

up(async = false)
Author Avatarabhimanyuaryan
11/26/2022, 5:53:39 PM

I haven't personally used force_compile what do you think it does and what are you trying achieve? I'll have a look

Author AvatarWheredNateGo
11/29/2022, 4:45:33 PM

I put it at the end of my routes.jl file with a 10 second delay. It seems to be working as expected as long as I run up() quickly after bin\repl.

Author Avataressenciary
11/29/2022, 4:53:12 PM

if the server is not running then it won't respond to the requests you're making

Author Avataressenciary
11/29/2022, 4:53:54 PM

force_compile running async won't crash the app but it won't have any effect on the compilation either

Author AvatarWheredNateGo
11/29/2022, 5:01:58 PM

That works for me. Thanks so much!