Browse Source

En cours de développement

master
mls-361 1 year ago
parent
commit
aa4a25b08f
  1. 29
      internal/engine/engine.go
  2. 36
      internal/supervisor/supervisor.go

29
internal/engine/engine.go

@ -17,26 +17,30 @@ import (
// Engine AFAIRE.
type Engine struct {
app *application.Application
cfg *config.Config
stopCh chan struct{}
endCh chan error
swg sync.WaitGroup
logger logger.Logger
app *application.Application
config *config.Config
configCh chan bool
stopCh chan struct{}
endCh chan error
swg sync.WaitGroup
logger logger.Logger
}
// New AFAIRE.
func New(app *application.Application, cfg *config.Config) *Engine {
func New(app *application.Application, config *config.Config) *Engine {
return &Engine{
app: app,
cfg: cfg,
stopCh: make(chan struct{}),
endCh: make(chan error, 1),
app: app,
config: config,
configCh: make(chan bool),
stopCh: make(chan struct{}),
endCh: make(chan error, 1),
}
}
// ConfigHasChanged AFAIRE.
func (e *Engine) ConfigHasChanged() {}
func (e *Engine) ConfigHasChanged() {
e.configCh <- true
}
// EndCh AFAIRE.
func (e *Engine) EndCh() <-chan error {
@ -52,6 +56,7 @@ func (e *Engine) loop() {
loop:
for {
select {
case <-e.configCh:
case <-e.stopCh:
break loop
}

36
internal/supervisor/supervisor.go

@ -22,25 +22,25 @@ import (
// Supervisor AFAIRE.
type Supervisor struct {
app *application.Application
cfg *config.Config
ege *engine.Engine
config *config.Config
engine *engine.Engine
logger logger.Logger
}
// New AFAIRE.
func New(app *application.Application) *Supervisor {
cfg := config.New(app)
ege := engine.New(app, cfg)
config := config.New(app)
engine := engine.New(app, config)
return &Supervisor{
app: app,
cfg: cfg,
ege: ege,
app: app,
config: config,
engine: engine,
}
}
func (s *Supervisor) supervise() time.Duration {
cfgVersion, err := s.cfg.HasChanged()
cfgVersion, err := s.config.HasChanged()
if err != nil {
d := 10 * time.Minute
@ -59,7 +59,7 @@ func (s *Supervisor) supervise() time.Duration {
s.logger.Notice("The configuration has changed", "version", cfgVersion) //::::::::::::::::::::::::::::::::::::::::::
s.ege.ConfigHasChanged()
s.engine.ConfigHasChanged()
return 5 * time.Minute
}
@ -73,25 +73,27 @@ func (s *Supervisor) loop() error {
end := false
ticker := time.NewTicker(time.Millisecond)
timer := time.NewTimer(0)
for {
select {
case <-ticker.C:
ticker.Reset(s.supervise())
case <-timer.C:
timer.Reset(s.supervise())
case <-endCh:
if end {
break
}
ticker.Stop()
s.ege.Stop()
if !timer.Stop() {
<-timer.C
}
s.engine.Stop()
end = true
case err := <-s.ege.EndCh():
s.ege.Wait()
case err := <-s.engine.EndCh():
s.engine.Wait()
return err
}
}
@ -123,7 +125,7 @@ func (s *Supervisor) Run() error {
logger.Info("END", "uptime", time.Since(app.StartedAt()).String()) //:::::::::::::::::::::::::::::::::::::::::::
}()
s.ege.Start(logger)
s.engine.Start(logger)
return s.loop()
}

Loading…
Cancel
Save