mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 09:04:27 +00:00
Implement last request time tracking for instance management
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -86,6 +87,9 @@ type Process struct {
|
|||||||
// Restart control
|
// Restart control
|
||||||
restartCancel context.CancelFunc `json:"-"` // Cancel function for pending restarts
|
restartCancel context.CancelFunc `json:"-"` // Cancel function for pending restarts
|
||||||
monitorDone chan struct{} `json:"-"` // Channel to signal monitor goroutine completion
|
monitorDone chan struct{} `json:"-"` // Channel to signal monitor goroutine completion
|
||||||
|
|
||||||
|
// Timeout management
|
||||||
|
lastRequestTime atomic.Int64 // Unix timestamp of last request
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateAndCopyOptions validates and creates a deep copy of the provided options
|
// validateAndCopyOptions validates and creates a deep copy of the provided options
|
||||||
|
|||||||
@@ -140,6 +140,15 @@ 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()
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
package instance
|
|
||||||
@@ -472,6 +472,9 @@ func (h *Handler) ProxyToInstance() http.HandlerFunc {
|
|||||||
proxyPath = "/" + proxyPath
|
proxyPath = "/" + proxyPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the last request time for the instance
|
||||||
|
inst.UpdateLastRequestTime()
|
||||||
|
|
||||||
// Modify the request to remove the proxy prefix
|
// Modify the request to remove the proxy prefix
|
||||||
originalPath := r.URL.Path
|
originalPath := r.URL.Path
|
||||||
r.URL.Path = proxyPath
|
r.URL.Path = proxyPath
|
||||||
@@ -582,6 +585,9 @@ func (h *Handler) OpenAIProxy() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update last request time for the instance
|
||||||
|
inst.UpdateLastRequestTime()
|
||||||
|
|
||||||
// Recreate the request body from the bytes we read
|
// Recreate the request body from the bytes we read
|
||||||
r.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
r.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||||
r.ContentLength = int64(len(bodyBytes))
|
r.ContentLength = int64(len(bodyBytes))
|
||||||
|
|||||||
Reference in New Issue
Block a user