Skip to content

Commit

Permalink
BCF-2687: start plugins without delay (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 9, 2023
1 parent 9d58ef1 commit 65aceb8
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions pkg/loop/plugin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,25 @@ func (s *pluginService[P, S]) init(pluginName string, p P, newService func(conte
func (s *pluginService[P, S]) keepAlive() {
defer s.wg.Done()

s.lggr.Debugw("Staring keepAlive", "tick", keepAliveTickDuration)
s.lggr.Debugw("Starting keepAlive", "tick", keepAliveTickDuration)

check := func() {
c := s.client
cp := s.clientProtocol
if c != nil && !c.Exited() && cp != nil {
// launched
err := cp.Ping()
if err == nil {
return // healthy
}
s.lggr.Errorw("Relaunching unhealthy plugin", "err", err)
}
if err := s.tryLaunch(cp); err != nil {
s.lggr.Errorw("Failed to launch plugin", "err", err)
}
}

check() // no delay

t := time.NewTicker(keepAliveTickDuration)
defer t.Stop()
Expand All @@ -76,19 +94,7 @@ func (s *pluginService[P, S]) keepAlive() {
case <-s.stopCh:
return
case <-t.C:
c := s.client
cp := s.clientProtocol
if c != nil && !c.Exited() && cp != nil {
// launched
err := cp.Ping()
if err == nil {
continue // healthy
}
s.lggr.Errorw("Relaunching unhealthy plugin", "err", err)
}
if err := s.tryLaunch(cp); err != nil {
s.lggr.Errorw("Failed to launch plugin", "err", err)
}
check()
case fn := <-s.testInterrupt:
fn(s)
}
Expand Down

0 comments on commit 65aceb8

Please sign in to comment.