101 lines
1.9 KiB
Go
101 lines
1.9 KiB
Go
// backend/myfreecams_lookup_pause.go
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const mfcLookupBusyCooldown = 10 * time.Minute
|
|
|
|
var (
|
|
mfcLookupPauseMu sync.Mutex
|
|
mfcLookupPausedUntil time.Time
|
|
mfcLookupPauseReason string
|
|
)
|
|
|
|
func isMFCServersBusyMessage(msg string) bool {
|
|
msg = strings.ToLower(strings.TrimSpace(msg))
|
|
return strings.Contains(msg, "servers busy")
|
|
}
|
|
|
|
func pauseMFCLookups(reason string, d time.Duration) {
|
|
if d <= 0 {
|
|
d = mfcLookupBusyCooldown
|
|
}
|
|
|
|
reason = strings.TrimSpace(reason)
|
|
if reason == "" {
|
|
reason = "servers busy"
|
|
}
|
|
|
|
until := time.Now().Add(d)
|
|
|
|
mfcLookupPauseMu.Lock()
|
|
changed := until.After(mfcLookupPausedUntil)
|
|
if changed {
|
|
mfcLookupPausedUntil = until
|
|
mfcLookupPauseReason = reason
|
|
}
|
|
mfcLookupPauseMu.Unlock()
|
|
|
|
if changed {
|
|
appLogln(
|
|
"⏸️ [myfreecams] usernameLookup pausiert bis",
|
|
until.Format("15:04:05"),
|
|
"Grund:",
|
|
reason,
|
|
)
|
|
}
|
|
}
|
|
|
|
func mfcLookupsPaused() (until time.Time, reason string, paused bool) {
|
|
mfcLookupPauseMu.Lock()
|
|
defer mfcLookupPauseMu.Unlock()
|
|
|
|
now := time.Now()
|
|
if mfcLookupPausedUntil.IsZero() || now.After(mfcLookupPausedUntil) {
|
|
mfcLookupPausedUntil = time.Time{}
|
|
mfcLookupPauseReason = ""
|
|
return time.Time{}, "", false
|
|
}
|
|
|
|
return mfcLookupPausedUntil, mfcLookupPauseReason, true
|
|
}
|
|
|
|
func mfcLookupPausedError() error {
|
|
until, reason, paused := mfcLookupsPaused()
|
|
if !paused {
|
|
return nil
|
|
}
|
|
|
|
if reason == "" {
|
|
reason = "servers busy"
|
|
}
|
|
|
|
return appErrorf(
|
|
"mfc usernameLookup pausiert bis %s: %s",
|
|
until.Format("15:04:05"),
|
|
reason,
|
|
)
|
|
}
|
|
|
|
func clearMFCLookupPause(reason string) {
|
|
reason = strings.TrimSpace(reason)
|
|
if reason == "" {
|
|
reason = "manual refresh"
|
|
}
|
|
|
|
mfcLookupPauseMu.Lock()
|
|
wasPaused := !mfcLookupPausedUntil.IsZero()
|
|
mfcLookupPausedUntil = time.Time{}
|
|
mfcLookupPauseReason = ""
|
|
mfcLookupPauseMu.Unlock()
|
|
|
|
if wasPaused {
|
|
appLogln("▶️ [myfreecams] usernameLookup Pause aufgehoben. Grund:", reason)
|
|
}
|
|
}
|