Open frederikhors opened 2 years ago
Hey @frederikhors, I don't think there's an option to kill a daemon when prep starts. Could you go into more detail about your use case and why this would be useful? Thanks!
I'm not the original person with the issue, but I believe I understand the use case.
Imagine that our application is a webserver and we are using modd to hot reload changes. So we have our app in, say, port 3000 and we make a change that actually has a syntax error or could not compile for a particular reason, but we did not notice it. We then hit our endpoint and it actually works because it is using the last binary that successfully built. It may be a little confusing to find why our changes are not being reflected because we did not see it failed to compile. The application actually cannot compile, but it is working.
There is a similar tool called air that supports stopping the daemon by the option "stop_on_error", but air is exclusive to go apps, while modd is more generic.
I myself tried workarouds, like deleting the binary when the build failed, like so:
**/*.go {
prep: go build -o main . || rm main
daemon: ./main
}
The problem is that the daemon runs anyways, and it simply fails because the file "main" does not exist, and it keeps trying indefinitely.
I also tried to put the build inside the daemon, but not only this feels silly and misusing the tool, it also had the problem of trying indefinitely to rebuild the whole application, which is a even worse than the previous workaround:
**/*.go {
daemon: go build -o main . && ./main
}
We could make more complicated shell commands, like create a temporary file to flag that we failed at building and don't try again unless something changed etc, but it keeps getting more and more dark and hacky. So I also feel like it would be a very nice addition to have something like "stop_on_error" option for modd, since air is a golang exclusive thing.
I have this simple modd.conf:
It works amazing.
But sometimes if I change a
.go
file and it couldn't build (because there is an error in the code) and it exit with error the daemon is still up and running.Is there a way to kill daemon when prep starts and to stop execution of the entire block if that prep (or others after it) fails?