61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package scopes
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"git.sr.ht/~cco/go-scopes/config"
|
|
"git.sr.ht/~cco/go-scopes/lib"
|
|
)
|
|
|
|
type Cfg struct {
|
|
*config.Base
|
|
AppType string
|
|
Home string
|
|
}
|
|
|
|
func Start(ctx lib.Context) {
|
|
lib.RunCtx(ctx, start)
|
|
}
|
|
|
|
func start(ctx lib.Context) {
|
|
defer ctx.Stop()
|
|
for _, cfg := range ctx.Config().Children() {
|
|
cctx := ctx.ChildContext(cfg)
|
|
cfg.Starter()(cctx)
|
|
fmt.Println(cfg.Name(), " started")
|
|
}
|
|
fmt.Println("running ", ctx.WaitGroup())
|
|
sig := make(chan os.Signal, 1)
|
|
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
|
for step(ctx, sig) {
|
|
}
|
|
}
|
|
|
|
func step(ctx lib.Context, sig <-chan os.Signal) bool {
|
|
select {
|
|
case <-sig:
|
|
fmt.Println("interrupted")
|
|
//ctx.LogInfo("Dispatcher interrupted", m.Map{})
|
|
return false
|
|
case msg := <-ctx.Mailbox():
|
|
fmt.Println("message", msg)
|
|
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
|
|
if msg == "quit" {
|
|
//ctx.LogInfo("Dispatcher stopped", m.Map{})
|
|
return false
|
|
}
|
|
//ctx.HandleMsg(&msg)
|
|
}
|
|
return true
|
|
}
|
|
|
|
// definitions
|
|
|
|
func RunApp(cfg lib.Config) {
|
|
ctx := lib.AppContext(cfg)
|
|
cfg.Starter()(ctx)
|
|
ctx.WaitGroup().Wait()
|
|
}
|