Commit b6bb454
internal/aod/main.go
@@ -11,10 +11,10 @@ import (
func Watch(domain string, die bool) error {
const (
- _targetPort uint16 = 25565
- _checkInterval time.Duration = time.Second * 5
- _logInterval time.Duration = time.Minute * 5
- _inactiveTimeout time.Duration = time.Minute * 55
+ _targetPort uint16 = 25565
+ _checkInterval time.Duration = time.Second * 5
+ _logInterval time.Duration = time.Minute * 5
+ _defaultTimeout time.Duration = time.Minute * 55
)
ticker := time.NewTicker(_checkInterval)
@@ -29,6 +29,7 @@ func Watch(domain string, die bool) error {
lastActive := time.Now()
lastLog := time.Now()
connections := -1 // log first active connection check
+ inactiveTimeout := _defaultTimeout
for {
select {
case <-ticker.C:
@@ -47,13 +48,14 @@ func Watch(domain string, die bool) error {
msg := "inactive"
details := []slog.Attr{
slog.String("duration", inactiveDuration.String()),
- slog.String("timeout", _inactiveTimeout.String()),
+ slog.String("timeout", inactiveTimeout.String()),
}
// reset if active
if connections != 0 {
lastActive = time.Now()
inactiveDuration = 0
+ inactiveTimeout = _defaultTimeout
msg = "active"
details = []slog.Attr{
slog.Int("connections", connections),
@@ -66,7 +68,7 @@ func Watch(domain string, die bool) error {
lastLog = time.Now()
}
- if inactiveDuration > _inactiveTimeout {
+ if inactiveDuration > inactiveTimeout {
if die {
msg = "inactive timeout: powering off"
slog.LogAttrs(context.Background(), slog.LevelInfo, msg, details...)
@@ -74,6 +76,7 @@ func Watch(domain string, die bool) error {
}
msg = "inactive timeout"
slog.LogAttrs(context.Background(), slog.LevelInfo, msg, details...)
+ inactiveTimeout = inactiveTimeout * 2
}
}
}
mm
Binary file