mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 09:04:27 +00:00
Make StartInstance and StopInstance idempotent
This commit is contained in:
@@ -383,8 +383,9 @@ func (im *instanceManager) StartInstance(name string) (*instance.Instance, error
|
|||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
|
// Idempotent: if already running, just return success
|
||||||
if inst.IsRunning() {
|
if inst.IsRunning() {
|
||||||
return inst, fmt.Errorf("instance with name %s is already running", name)
|
return inst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check max running instances limit for local instances only
|
// Check max running instances limit for local instances only
|
||||||
@@ -446,8 +447,9 @@ func (im *instanceManager) StopInstance(name string) (*instance.Instance, error)
|
|||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
|
// Idempotent: if already stopped, just return success
|
||||||
if !inst.IsRunning() {
|
if !inst.IsRunning() {
|
||||||
return inst, fmt.Errorf("instance with name %s is already stopped", name)
|
return inst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := inst.Stop(); err != nil {
|
if err := inst.Stop(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user