Enforce maximum running instances limit in StartInstance method

This commit is contained in:
2025-08-27 21:18:38 +02:00
parent ae37055331
commit 0b058237fe

View File

@@ -181,6 +181,10 @@ func (im *instanceManager) StartInstance(name string) (*instance.Process, error)
return instance, fmt.Errorf("instance with name %s is already running", name) return instance, fmt.Errorf("instance with name %s is already running", name)
} }
if len(im.runningInstances) >= im.instancesConfig.MaxRunningInstances && im.instancesConfig.MaxRunningInstances != -1 {
return nil, fmt.Errorf("maximum number of running instances (%d) reached", im.instancesConfig.MaxRunningInstances)
}
if err := instance.Start(); err != nil { if err := instance.Start(); err != nil {
return nil, fmt.Errorf("failed to start instance %s: %w", name, err) return nil, fmt.Errorf("failed to start instance %s: %w", name, err)
} }