mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Initialize last request time on instance start and update timeout handling logic
This commit is contained in:
@@ -30,6 +30,9 @@ func (i *Process) Start() error {
|
|||||||
i.restarts = 0
|
i.restarts = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize last request time to current time when starting
|
||||||
|
i.lastRequestTime.Store(time.Now().Unix())
|
||||||
|
|
||||||
// Create log files
|
// Create log files
|
||||||
if err := i.logger.Create(); err != nil {
|
if err := i.logger.Create(); err != nil {
|
||||||
return fmt.Errorf("failed to create log files: %w", err)
|
return fmt.Errorf("failed to create log files: %w", err)
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ func (i *Process) ShouldTimeout() bool {
|
|||||||
|
|
||||||
// Check if the last request time exceeds the idle timeout
|
// Check if the last request time exceeds the idle timeout
|
||||||
lastRequest := i.lastRequestTime.Load()
|
lastRequest := i.lastRequestTime.Load()
|
||||||
idleTimeout := *i.options.IdleTimeout
|
idleTimeoutMinutes := *i.options.IdleTimeout
|
||||||
|
|
||||||
return (time.Now().Unix() - lastRequest) > int64(idleTimeout)
|
// Convert timeout from minutes to seconds for comparison
|
||||||
|
idleTimeoutSeconds := int64(idleTimeoutMinutes * 60)
|
||||||
|
|
||||||
|
return (time.Now().Unix() - lastRequest) > idleTimeoutSeconds
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,23 @@ import "log"
|
|||||||
|
|
||||||
func (im *instanceManager) checkAllTimeouts() {
|
func (im *instanceManager) checkAllTimeouts() {
|
||||||
im.mu.RLock()
|
im.mu.RLock()
|
||||||
defer im.mu.RUnlock()
|
var timeoutInstances []string
|
||||||
|
|
||||||
|
// Identify instances that should timeout
|
||||||
for _, inst := range im.instances {
|
for _, inst := range im.instances {
|
||||||
if inst.ShouldTimeout() {
|
if inst.ShouldTimeout() {
|
||||||
log.Printf("Instance %s has timed out, stopping it", inst.Name)
|
timeoutInstances = append(timeoutInstances, inst.Name)
|
||||||
if proc, err := im.StopInstance(inst.Name); err != nil {
|
}
|
||||||
log.Printf("Error stopping instance %s: %v", inst.Name, err)
|
}
|
||||||
} else {
|
im.mu.RUnlock() // Release read lock before calling StopInstance
|
||||||
log.Printf("Instance %s stopped successfully, process: %v", inst.Name, proc)
|
|
||||||
}
|
// Stop the timed-out instances
|
||||||
|
for _, name := range timeoutInstances {
|
||||||
|
log.Printf("Instance %s has timed out, stopping it", name)
|
||||||
|
if proc, err := im.StopInstance(name); err != nil {
|
||||||
|
log.Printf("Error stopping instance %s: %v", name, err)
|
||||||
|
} else {
|
||||||
|
log.Printf("Instance %s stopped successfully, process: %v", name, proc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user