Skip to content

Commit

Permalink
Make deleteProcess more idiomatic
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Oct 1, 2024
1 parent 6cc47cb commit b15b791
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions pkg/model/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ import (
)

func (ml *ModelLoader) deleteProcess(s string) error {
if m, exists := ml.models[s]; exists {
process := m.Process()
if process != nil {
if err := process.Stop(); err != nil {
log.Error().Err(err).Msgf("(deleteProcess) error while deleting process %s", s)
}
}
defer delete(ml.models, s)

m, exists := ml.models[s]
if !exists {
// Nothing to do
return nil
}

process := m.Process()
if process == nil {
// Nothing to do as there is no process
return nil
}
delete(ml.models, s)
return nil

err := process.Stop()
if err != nil {
log.Error().Err(err).Msgf("(deleteProcess) error while deleting process %s", s)
}

return err
}

func (ml *ModelLoader) StopGRPC(filter GRPCProcessFilter) error {
Expand Down

0 comments on commit b15b791

Please sign in to comment.