Assorted bug fixes
This commit is contained in:
parent
a58b5932e7
commit
0a4cc1143e
@ -36,6 +36,7 @@ type environment struct {
|
||||
ctx context.Context
|
||||
done context.CancelCauseFunc
|
||||
group sync.WaitGroup
|
||||
noneLeft chan struct { }
|
||||
conf MutableConfig
|
||||
cron *cron
|
||||
|
||||
@ -94,6 +95,8 @@ func (this *environment) Run(name, description string, actors ...Actor) {
|
||||
this.addToSetsInitial(actors...)
|
||||
this.addToSetsInitial(this.cron)
|
||||
|
||||
this.noneLeft = make(chan struct { })
|
||||
|
||||
if !this.phase10FlagParsing() { os.Exit(2) }
|
||||
if !this.phase13PidFileCreation() { os.Exit(1) }
|
||||
if !this.phase17PrivilegeDropping() { os.Exit(1) }
|
||||
@ -118,6 +121,17 @@ func (this *environment) Add(ctx context.Context, actors ...Actor) error {
|
||||
this.delFromSets(actors...)
|
||||
}
|
||||
|
||||
for _, actor := range actors {
|
||||
if actor, ok := actor.(Configurable); ok {
|
||||
err := actor.Configure(this.conf)
|
||||
if err != nil {
|
||||
cleanUp()
|
||||
return fmt.Errorf (
|
||||
"could not apply configuration to %s: %w",
|
||||
actor.(Actor).Type(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
initializable := make([]Initializable, 0, len(actors))
|
||||
for _, actor := range actors {
|
||||
if actor, ok := actor.(Initializable); ok {
|
||||
@ -132,17 +146,6 @@ func (this *environment) Add(ctx context.Context, actors ...Actor) error {
|
||||
cleanUp()
|
||||
return err
|
||||
}
|
||||
for _, actor := range actors {
|
||||
if actor, ok := actor.(Configurable); ok {
|
||||
err := actor.Configure(this.conf)
|
||||
if err != nil {
|
||||
cleanUp()
|
||||
return fmt.Errorf (
|
||||
"could not apply configuration to %s: %w",
|
||||
actor.(Actor).Type(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, actor := range actors {
|
||||
_, isRunnable := actor.(Runnable)
|
||||
_, isRunShutdownable := actor.(RunShutdownable)
|
||||
|
||||
10
phases.go
10
phases.go
@ -200,7 +200,7 @@ func (this *environment) phase50ConfigurationApplication() bool {
|
||||
defer done()
|
||||
for _, actor := range sortActors(actors, actors.configurable.all()) {
|
||||
if !actors.info(actor.(Actor)).initial { continue }
|
||||
if this.Verb() { log.Println ("... (50) applying configuration to %s", actor.(Actor).Type())}
|
||||
if this.Verb() { log.Printf ("... (50) applying configuration to %s", actor.(Actor).Type())}
|
||||
err := actor.Configure(this.conf)
|
||||
if err != nil {
|
||||
log.Printf (
|
||||
@ -288,15 +288,14 @@ func (this *environment) phase70RunningBody() bool {
|
||||
}()
|
||||
log.Println(".// (70) startup sequence complete")
|
||||
// await context cancellation or waitgroup completion
|
||||
wgChannel := make(chan struct { }, 1)
|
||||
go func() {
|
||||
this.group.Wait()
|
||||
wgChannel <- struct { } { }
|
||||
close(this.noneLeft)
|
||||
}()
|
||||
select {
|
||||
case <- this.ctx.Done():
|
||||
if this.Verb() { log.Println("(i) (70) canceled") }
|
||||
case <- wgChannel:
|
||||
case <- this.noneLeft:
|
||||
if this.Verb() { log.Println("(i) (70) all actors have finished") }
|
||||
}
|
||||
return true
|
||||
@ -358,6 +357,7 @@ func (this *environment) phase80Shutdown() bool {
|
||||
log.Println(".// (80) shutdown succeeded, goodbye")
|
||||
log.Printf("====== [%s] END =======", this.name)
|
||||
}()
|
||||
this.group.Wait()
|
||||
// wait for all actors to shut down
|
||||
<- this.noneLeft
|
||||
return cause == nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user