diff --git a/.ozai.json b/.ozai.json index a8c1f00..b734619 100644 --- a/.ozai.json +++ b/.ozai.json @@ -1,8 +1,14 @@ { "Processes": { - "ssgod": { - "Name": "ssgod", - "Command": "ssgod" + "tester1": { + "Name": "tester", + "Command": "tester", + "Args": ["-count", "2", "-id", "1"] + }, + "tester2": { + "Name": "tester", + "Command": "tester", + "Args": ["-count", "5", "-id", "2"] } } } diff --git a/Makefile b/Makefile index a81ee69..63387fa 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,16 @@ ifeq '$(OS)' 'Windows_NT' GO_IS_STUPID_EXE=.exe endif -build: +build: build_tester go build . test: go test lcthw.dev/learn-code-the-hard-way/ozai/tests -c -o runtests$(GO_IS_STUPID_EXE) ./runtests$(GO_IS_STUPID_EXE) +build_tester: + go build -o tester$(GO_IS_STUPID_EXE) ./tools/cmd/tester/main.go + docs: go tool pkgsite --open diff --git a/config/settings.go b/config/settings.go index db0bb8d..bee63c0 100644 --- a/config/settings.go +++ b/config/settings.go @@ -10,6 +10,7 @@ import ( type command struct { Command string + Args []string } type config struct { diff --git a/go.mod b/go.mod index c4e3f70..c518542 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module lcthw.dev/learn-code-the-hard-way/ozai go 1.24.2 -require github.com/BurntSushi/toml v1.5.0 - require ( github.com/google/licensecheck v0.3.1 // indirect github.com/google/safehtml v0.0.3-0.20211026203422-d6f0e11a5516 // indirect diff --git a/go.sum b/go.sum index 63d2e0b..f0d4b16 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= -github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/licensecheck v0.3.1 h1:QoxgoDkaeC4nFrtGN1jV7IPmDCHFNIVh54e5hSt6sPs= diff --git a/main.go b/main.go index 7208d88..959e1fa 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "os/exec" "log" "errors" + "sync" "lcthw.dev/learn-code-the-hard-way/ozai/config" ) @@ -13,18 +14,35 @@ func main() { fmt.Println("CONFIG:", config.Settings.ConfigPath) fmt.Println("COMMANDs:", config.Settings.Processes) + var wg sync.WaitGroup - cmd := exec.Command(config.Settings.Processes["ssgod"].Command) - if errors.Is(cmd.Err, exec.ErrDot) { - cmd.Err = nil - } + for name, proc := range config.Settings.Processes { + fmt.Println("PROCESS:", name) + wg.Add(1) + + go func() { + defer wg.Done() + + for { + fmt.Println("STARTING", name) + cmd := exec.Command(proc.Command, proc.Args...) + if errors.Is(cmd.Err, exec.ErrDot) { + cmd.Err = nil + } + + out, err := cmd.CombinedOutput() - out, err := cmd.CombinedOutput() + if err != nil { + fmt.Printf("%s\n", out) + log.Fatal(err) + } - if err != nil { - fmt.Printf("%s\n", out) - log.Fatal(err) + fmt.Println("WAITING for", name) + cmd.Wait() + fmt.Println("PROC", name, "EXITED SEND QUIT") + } + }() } - cmd.Wait() + wg.Wait() } diff --git a/tools/cmd/tester/main.go b/tools/cmd/tester/main.go new file mode 100644 index 0000000..a90df63 --- /dev/null +++ b/tools/cmd/tester/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "time" + "flag" +) + +func main() { + + count := flag.Int("count", 10, "Seconds to wait") + id := flag.Int("id", 1, "Tester ID to use.") + + for i := 0; i < *count; i++ { + time.Sleep(1 * time.Second) + fmt.Println("TICK", *id) + } +}