Add OnDemandStartTimeout configuration and update OpenAIProxy to use it

This commit is contained in:
2025-08-20 14:25:43 +02:00
parent 496ab3aa5d
commit ddb54763f6
2 changed files with 12 additions and 3 deletions

View File

@@ -70,6 +70,9 @@ type InstancesConfig struct {
// Default on-demand start setting for new instances
DefaultOnDemandStart bool `yaml:"default_on_demand_start"`
// How long to wait for an instance to start on demand (in seconds)
OnDemandStartTimeout int `yaml:"on_demand_start_timeout,omitempty"`
// Interval for checking instance timeouts (in minutes)
TimeoutCheckInterval int `yaml:"timeout_check_interval"`
}
@@ -114,8 +117,9 @@ func LoadConfig(configPath string) (AppConfig, error) {
DefaultAutoRestart: true,
DefaultMaxRestarts: 3,
DefaultRestartDelay: 5,
DefaultOnDemandStart: false,
TimeoutCheckInterval: 5, // Check timeouts every 5 minutes
DefaultOnDemandStart: true,
OnDemandStartTimeout: 120, // 2 minutes
TimeoutCheckInterval: 5, // Check timeouts every 5 minutes
},
Auth: AuthConfig{
RequireInferenceAuth: true,
@@ -230,6 +234,11 @@ func loadEnvVars(cfg *AppConfig) {
cfg.Instances.DefaultOnDemandStart = b
}
}
if onDemandTimeout := os.Getenv("LLAMACTL_ON_DEMAND_START_TIMEOUT"); onDemandTimeout != "" {
if seconds, err := strconv.Atoi(onDemandTimeout); err == nil {
cfg.Instances.OnDemandStartTimeout = seconds
}
}
if timeoutCheckInterval := os.Getenv("LLAMACTL_TIMEOUT_CHECK_INTERVAL"); timeoutCheckInterval != "" {
if minutes, err := strconv.Atoi(timeoutCheckInterval); err == nil {
cfg.Instances.TimeoutCheckInterval = minutes

View File

@@ -583,7 +583,7 @@ func (h *Handler) OpenAIProxy() http.HandlerFunc {
}
// Wait for the instance to become healthy before proceeding
if err := inst.WaitForHealthy(120); err != nil { // 2 minutes timeout
if err := inst.WaitForHealthy(h.cfg.Instances.OnDemandStartTimeout); err != nil { // 2 minutes timeout
http.Error(w, "Instance failed to become healthy: "+err.Error(), http.StatusServiceUnavailable)
return
}