mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 09:04:27 +00:00
Update CreateInstanceOptions to use pointers for optional fields and set defaults in NewInstance
This commit is contained in:
@@ -44,9 +44,9 @@ func (d Duration) ToDuration() time.Duration {
|
|||||||
|
|
||||||
type CreateInstanceOptions struct {
|
type CreateInstanceOptions struct {
|
||||||
// Auto restart
|
// Auto restart
|
||||||
AutoRestart bool `json:"auto_restart,omitempty"`
|
AutoRestart *bool `json:"auto_restart,omitempty"`
|
||||||
MaxRestarts int `json:"max_restarts,omitempty"`
|
MaxRestarts *int `json:"max_restarts,omitempty"`
|
||||||
RestartDelay Duration `json:"restart_delay,omitempty"` // Duration in seconds
|
RestartDelay *Duration `json:"restart_delay,omitempty"` // Duration in seconds
|
||||||
|
|
||||||
LlamaServerOptions `json:",inline"`
|
LlamaServerOptions `json:",inline"`
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,19 @@ type Instance struct {
|
|||||||
|
|
||||||
// NewInstance creates a new instance with the given name, log path, and options
|
// NewInstance creates a new instance with the given name, log path, and options
|
||||||
func NewInstance(name string, globalSettings *InstancesConfig, options *CreateInstanceOptions) *Instance {
|
func NewInstance(name string, globalSettings *InstancesConfig, options *CreateInstanceOptions) *Instance {
|
||||||
|
if options.AutoRestart == nil {
|
||||||
|
defaultAutoRestart := globalSettings.DefaultAutoRestart
|
||||||
|
options.AutoRestart = &defaultAutoRestart
|
||||||
|
}
|
||||||
|
if options.MaxRestarts == nil {
|
||||||
|
defaultMaxRestarts := globalSettings.DefaultMaxRestarts
|
||||||
|
options.MaxRestarts = &defaultMaxRestarts
|
||||||
|
}
|
||||||
|
if options.RestartDelay == nil {
|
||||||
|
defaultRestartDelay := globalSettings.DefaultRestartDelay
|
||||||
|
options.RestartDelay = &defaultRestartDelay
|
||||||
|
}
|
||||||
|
|
||||||
return &Instance{
|
return &Instance{
|
||||||
Name: name,
|
Name: name,
|
||||||
options: options,
|
options: options,
|
||||||
@@ -317,7 +330,7 @@ func (i *Instance) monitorProcess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle restart if process crashed and auto-restart is enabled
|
// Handle restart if process crashed and auto-restart is enabled
|
||||||
if err != nil && i.options.AutoRestart && i.restarts < i.options.MaxRestarts {
|
if err != nil && *i.options.AutoRestart && i.restarts < *i.options.MaxRestarts {
|
||||||
i.restarts++
|
i.restarts++
|
||||||
log.Printf("Auto-restarting instance %s (attempt %d/%d) in %v",
|
log.Printf("Auto-restarting instance %s (attempt %d/%d) in %v",
|
||||||
i.Name, i.restarts, i.options.MaxRestarts, i.options.RestartDelay.ToDuration())
|
i.Name, i.restarts, i.options.MaxRestarts, i.options.RestartDelay.ToDuration())
|
||||||
@@ -334,7 +347,7 @@ func (i *Instance) monitorProcess() {
|
|||||||
log.Printf("Successfully restarted instance %s", i.Name)
|
log.Printf("Successfully restarted instance %s", i.Name)
|
||||||
i.restarts = 0 // Reset restart count on successful restart
|
i.restarts = 0 // Reset restart count on successful restart
|
||||||
}
|
}
|
||||||
} else if i.restarts >= i.options.MaxRestarts {
|
} else if i.restarts >= *i.options.MaxRestarts {
|
||||||
log.Printf("Instance %s exceeded max restart attempts (%d)", i.Name, i.options.MaxRestarts)
|
log.Printf("Instance %s exceeded max restart attempts (%d)", i.Name, i.options.MaxRestarts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user