mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Move UpdateLastRequestTime method to timeout.go and add ShouldTimeout method for idle timeout handling
This commit is contained in:
@@ -140,15 +140,6 @@ func (i *Process) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLastRequestTime updates the last request access time for the instance via proxy
|
|
||||||
func (i *Process) UpdateLastRequestTime() {
|
|
||||||
i.mu.Lock()
|
|
||||||
defer i.mu.Unlock()
|
|
||||||
|
|
||||||
lastRequestTime := time.Now().Unix()
|
|
||||||
i.lastRequestTime.Store(lastRequestTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Process) monitorProcess() {
|
func (i *Process) monitorProcess() {
|
||||||
defer func() {
|
defer func() {
|
||||||
i.mu.Lock()
|
i.mu.Lock()
|
||||||
|
|||||||
28
pkg/instance/timeout.go
Normal file
28
pkg/instance/timeout.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package instance
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// UpdateLastRequestTime updates the last request access time for the instance via proxy
|
||||||
|
func (i *Process) UpdateLastRequestTime() {
|
||||||
|
i.mu.Lock()
|
||||||
|
defer i.mu.Unlock()
|
||||||
|
|
||||||
|
lastRequestTime := time.Now().Unix()
|
||||||
|
i.lastRequestTime.Store(lastRequestTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Process) ShouldTimeout() bool {
|
||||||
|
i.mu.RLock()
|
||||||
|
defer i.mu.RUnlock()
|
||||||
|
|
||||||
|
// If idle timeout is not set, no timeout
|
||||||
|
if i.options.IdleTimeout == nil || *i.options.IdleTimeout <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the last request time exceeds the idle timeout
|
||||||
|
lastRequest := i.lastRequestTime.Load()
|
||||||
|
idleTimeout := *i.options.IdleTimeout
|
||||||
|
|
||||||
|
return (time.Now().Unix() - lastRequest) > int64(idleTimeout)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user