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.
 
 
 

99 lines
2.5 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### supervisor ####### Copyright (c) 2021 mls-361 ############################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package supervisor
import (
"os"
"time"
"forge.chapril.org/mls-361/application"
"forge.chapril.org/mls-361/failure"
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/armen/armen/internal/config"
)
// Supervisor AFAIRE.
type Supervisor struct {
app *application.Application
config *config.Config
logger logger.Logger
}
// New AFAIRE.
func New(app *application.Application) *Supervisor {
return &Supervisor{
app: app,
config: config.New(app),
}
}
func (s *Supervisor) loadConfig() error {
complete, err := s.config.Load()
if err != nil {
return failure.Wrap(err, "unable to load configuration") ///////////////////////////////////////////////////////
}
if complete {
return nil
}
if err := s.config.LoadFromSource(); err != nil {
return failure.Wrap(err, "impossible to load the entire configuration") ////////////////////////////////////////
}
return nil
}
func (s *Supervisor) createComponents() error {
return nil
}
func (s *Supervisor) loop() {
}
// Run AFAIRE.
func (s *Supervisor) Run() error {
if err := s.loadConfig(); err != nil {
return failure.Wrap(err, "unable to load configuration") ///////////////////////////////////////////////////////
}
logger, err := s.createLogger()
if err != nil {
return failure.Wrap(err, "impossible to create the logger") ////////////////////////////////////////////////////
}
app := s.app
defer func() {
logger.Info("END", "uptime", time.Since(app.StartedAt()).Round(time.Second).String()) //::::::::::::::::::::::::
logger.Remove()
}()
logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"BEGIN",
"id", app.ID(),
"name", app.Name(),
"version", app.Version(),
"builtAt", app.BuiltAt().Format("2006-01-02 15:04:05"),
"pid", os.Getpid(),
)
s.logger = logger
if err := s.createComponents(); err != nil {
return failure.Wrap(err, "impossible to create the components") //::::::::::::::::::::::::::::::::::::::::::::::
}
s.loop()
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/