Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading server in development #12

Open
lpil opened this issue Aug 6, 2023 · 8 comments
Open

Reloading server in development #12

lpil opened this issue Aug 6, 2023 · 8 comments
Labels
later This is an issue to tackle later after other issues

Comments

@lpil
Copy link
Collaborator

lpil commented Aug 6, 2023

It would be good for the programmer not to have to ctrl-c and restart the server to see their changes.

How could we implement this? The Gleam build tool has to be run so perhaps this restart functionality wants to be built into the build tool itself, to be useful to all Gleam projects.

Or can a tool like watchexec be recommended? This would be great but when I tried it occasionally it wouldn't exit cleanly and I was unable to determine why that was. It would be fab if we could fix that issue.

We need proposals!

@lpil lpil added the later This is an issue to tackle later after other issues label Aug 6, 2023
@MystPi
Copy link

MystPi commented Aug 20, 2023

I think a watch option for the build tool itself would be neat! Not sure about watchexec as I haven't used it before, but I think having things built-in as opposed to having to download an external tool is usually preferable.

@lpil
Copy link
Collaborator Author

lpil commented Aug 20, 2023

For sure. We want it to be as easy as possible. Do you have thoughts on how this should work?

@MystPi
Copy link

MystPi commented Aug 21, 2023

I think a --watch or -w flag would work.

gleam run --watch

@lpil
Copy link
Collaborator Author

lpil commented Aug 21, 2023

Sorry, I don't mean what would the command line flag be, I mean what would it do and how would it be implemented. I don't know what is the right way to try and build this.

@MystPi
Copy link

MystPi commented Aug 21, 2023

Ah, my bad! I'm afraid I don't know much about how you would actually implement it, but maybe something like Hotwatch could help?

@lpil
Copy link
Collaborator Author

lpil commented Aug 21, 2023

There's options for listening for filesystem events in both Rust and Erlang, but I'm not sure exactly what should happen when one of these events occurs. It's a tricky one. It would be nice if we can keep the BEAM instance running like Elixir's Phoenix, but seeing as the compiler isn't available in Gleam like it is for Elixir it's a lot trickier. I'm also not sure our design would work as well with hot code loading.

@pta2002
Copy link

pta2002 commented Nov 17, 2023

We've discussed this in the discord in the past, but I'll just leave here that I made radiate to try to solve this.

It's fairly hacky since you can't access the compiler directly from gleam, but I guess it might not be too bad for development? Not sure.

Still -- websockets is needed to get this working reliably.

@markholmes
Copy link
Contributor

Until this is solved, I wanted to share my Makefile:

.PHONY: run

run:
	watchexec --restart --verbose --clear --wrap-process=session --stop-signal SIGTERM --exts gleam --watch src/ -- "gleam run"

This watches for any file changes under src/ and restarts the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
later This is an issue to tackle later after other issues
Projects
None yet
Development

No branches or pull requests

4 participants