Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

65 lines
1.3 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### supervisor ####### Copyright (c) 2021 mls-361 ############################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package supervisor
import (
"os"
"os/signal"
"syscall"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/engine"
)
// Supervisor AFAIRE.
type Supervisor struct {
config *config.Config
engine *engine.Engine
}
// New AFAIRE.
func New(c *config.Config, e *engine.Engine) *Supervisor {
return &Supervisor{
config: c,
engine: e,
}
}
func (s *Supervisor) loop() error {
endCh := make(chan os.Signal, 1)
defer close(endCh)
signal.Notify(endCh, os.Interrupt, syscall.SIGABRT, syscall.SIGQUIT, syscall.SIGTERM)
end := false
for {
select {
case err := <-s.engine.EndCh():
s.engine.Wait()
return err
case <-endCh:
if end {
break
}
s.engine.Stop()
}
}
}
// Run AFAIRE.
func (s *Supervisor) Run() error {
s.engine.Start()
return s.loop()
}
/*
######################################################################################################## @(°_°)@ #######
*/