Move proxy to separate struct

This commit is contained in:
2025-10-14 22:01:09 +02:00
parent 02909c5153
commit 92a76bc84b
4 changed files with 214 additions and 110 deletions

View File

@@ -1,28 +1,18 @@
package instance
// UpdateLastRequestTime updates the last request access time for the instance via proxy
// Delegates to the Proxy component
func (i *Process) UpdateLastRequestTime() {
i.mu.Lock()
defer i.mu.Unlock()
lastRequestTime := i.timeProvider.Now().Unix()
i.lastRequestTime.Store(lastRequestTime)
if i.proxy != nil {
i.proxy.UpdateLastRequestTime()
}
}
// ShouldTimeout checks if the instance should timeout based on idle time
// Delegates to the Proxy component
func (i *Process) ShouldTimeout() bool {
i.mu.RLock()
defer i.mu.RUnlock()
if !i.IsRunning() || i.options.IdleTimeout == nil || *i.options.IdleTimeout <= 0 {
if i.proxy == nil {
return false
}
// Check if the last request time exceeds the idle timeout
lastRequest := i.lastRequestTime.Load()
idleTimeoutMinutes := *i.options.IdleTimeout
// Convert timeout from minutes to seconds for comparison
idleTimeoutSeconds := int64(idleTimeoutMinutes * 60)
return (i.timeProvider.Now().Unix() - lastRequest) > idleTimeoutSeconds
return i.proxy.ShouldTimeout()
}