Initialize last request time on instance start and update timeout handling logic

This commit is contained in:
2025-08-17 21:15:28 +02:00
parent 5e3a28398d
commit c45fa13206
3 changed files with 22 additions and 9 deletions

View File

@@ -30,6 +30,9 @@ func (i *Process) Start() error {
i.restarts = 0
}
// Initialize last request time to current time when starting
i.lastRequestTime.Store(time.Now().Unix())
// Create log files
if err := i.logger.Create(); err != nil {
return fmt.Errorf("failed to create log files: %w", err)

View File

@@ -21,7 +21,10 @@ func (i *Process) ShouldTimeout() bool {
// Check if the last request time exceeds the idle timeout
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
}