diff --git a/TODO.md b/TODO.md index 9550158..cd150a3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,9 +1,17 @@ - [ ] Update check script: - - [ ] Run `go fmt` on all .go files - - [ ] Run prettier on all .ts files + - [x] shellcheck on shell scripts + - [x] `go vet` on go files + - [x] `golangci-lint` on go files + - [x] Run `go fmt` on all .go files - [ ] Eventually, run unit tests -- [ ] Adapt master program so that it reads configuration from command line +- [x] Reimplement fixup.sh + - [x] run shfmt on all shell scripts (and the files they `source`) + - [x] Run `go fmt` on all .go files + - [x] Run ~~prettier~~ biome on all .ts files and maybe others + + +- [x] Adapt master program so that it reads configuration from command line args instead of from environment variables - Should have sane defaults - Adding new arguments should be easy and obvious @@ -19,3 +27,9 @@ - [ ] update framework-managed pnpm - [ ] update pnpm-managed deps - [ ] rebuild golang programs + +- [ ] If the number of workers is large, then there is a long lapse between + when you change a file and when the server responds + - One solution: start and stop workers serially: stop one, restart it with new + code; repeat + - Slow start them: only start a few at first diff --git a/master/main.go b/master/main.go index 8867ba7..dd629da 100644 --- a/master/main.go +++ b/master/main.go @@ -1,30 +1,20 @@ package main import ( + "flag" "fmt" "os" "os/signal" - "strconv" "syscall" ) func main() { - watchedDir := os.Getenv("WATCHED_DIR") + watchDir := flag.String("watch", "../express", "directory to watch for changes") + workers := flag.Int("workers", 1, "number of worker processes") + basePort := flag.Int("base-port", 3000, "base port for worker processes") + listenPort := flag.Int("port", 8080, "port for the reverse proxy to listen on") - numChildProcesses := 1 - if n, err := strconv.Atoi(os.Getenv("NUM_CHILD_PROCESSES")); err == nil && n > 0 { - numChildProcesses = n - } - - basePort := 3000 - if p, err := strconv.Atoi(os.Getenv("BASE_PORT")); err == nil && p > 0 { - basePort = p - } - - listenPort := 8080 - if p, err := strconv.Atoi(os.Getenv("LISTEN_PORT")); err == nil && p > 0 { - listenPort = p - } + flag.Parse() // Create worker pool pool := NewWorkerPool() @@ -35,12 +25,12 @@ func main() { fileChanges := make(chan FileChange, 10) - go watchFiles(watchedDir, fileChanges) + go watchFiles(*watchDir, fileChanges) - go runExpress(fileChanges, numChildProcesses, basePort, pool) + go runExpress(fileChanges, *workers, *basePort, pool) // Start the reverse proxy - listenAddr := fmt.Sprintf(":%d", listenPort) + listenAddr := fmt.Sprintf(":%d", *listenPort) go startProxy(listenAddr, pool) // Wait for interrupt signal