Skip to content

Commit

Permalink
Use stopmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Nov 26, 2023
1 parent 1d5b496 commit 41fd3ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/model/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (ml *ModelLoader) LoadModel(modelName string, loader func(string, string) (
func (ml *ModelLoader) ShutdownModel(modelName string) error {
ml.mu.Lock()
defer ml.mu.Unlock()

return ml.StopModel(modelName)
}

func (ml *ModelLoader) StopModel(modelName string) error {
if _, ok := ml.models[modelName]; !ok {
return fmt.Errorf("model %s not found", modelName)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type WatchDog struct {
}

type ProcessManager interface {
ShutdownModel(modelName string) error
StopModel(modelName string) error
}

func NewWatchDog(pm ProcessManager, timeoutBusy, timeoutIdle time.Duration, busy, idle bool) *WatchDog {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (wd *WatchDog) checkIdle() {
log.Warn().Msgf("[WatchDog] Address %s is idle for too long, killing it", address)
p, ok := wd.addressModelMap[address]
if ok {
if err := wd.pm.ShutdownModel(p); err != nil {
if err := wd.pm.StopModel(p); err != nil {
log.Error().Msgf("[watchdog] Error shutting down model %s: %v", p, err)
}
delete(wd.idleTime, address)
Expand All @@ -139,7 +139,7 @@ func (wd *WatchDog) checkBusy() {
model, ok := wd.addressModelMap[address]
if ok {
log.Warn().Msgf("[WatchDog] Model %s is busy for too long, killing it", model)
if err := wd.pm.ShutdownModel(model); err != nil {
if err := wd.pm.StopModel(model); err != nil {
log.Error().Msgf("[watchdog] Error shutting down model %s: %v", model, err)
}
delete(wd.timetable, address)
Expand Down

0 comments on commit 41fd3ef

Please sign in to comment.