mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
Improved sleep prevention (#255)
* Added timeout before clear EXECUTION_STATE flags to give time on episodes changing. * Added timeout before clear EXECUTION_STATE flags to give time on episodes changing. --------- Co-authored-by: Anton Potekhin <anton.potekhin@orbitsoft.com>
This commit is contained in:
@@ -19,6 +19,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var pulseTime = 60 * time.Second
|
var pulseTime = 60 * time.Second
|
||||||
|
var clearFlagTimeout = 3 * 60 * time.Second
|
||||||
|
|
||||||
func Preconfig(kill bool) {
|
func Preconfig(kill bool) {
|
||||||
go func() {
|
go func() {
|
||||||
@@ -31,6 +32,7 @@ func Preconfig(kill bool) {
|
|||||||
normalExecutionState := uintptr(EsContinuous)
|
normalExecutionState := uintptr(EsContinuous)
|
||||||
systemRequireState := uintptr(EsSystemRequired | EsContinuous)
|
systemRequireState := uintptr(EsSystemRequired | EsContinuous)
|
||||||
pulse := time.NewTicker(pulseTime)
|
pulse := time.NewTicker(pulseTime)
|
||||||
|
var clearFlagTime int64 = -1
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-pulse.C:
|
case <-pulse.C:
|
||||||
@@ -51,8 +53,17 @@ func Preconfig(kill bool) {
|
|||||||
|
|
||||||
if !systemRequired && currentExecState != normalExecutionState {
|
if !systemRequired && currentExecState != normalExecutionState {
|
||||||
// Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
|
// Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
|
||||||
currentExecState = normalExecutionState
|
|
||||||
setThreadExecStateProc.Call(normalExecutionState)
|
// Avoid clear flag immediately to add time to start next episode
|
||||||
|
if clearFlagTime == -1 {
|
||||||
|
clearFlagTime = time.Now().Unix() + int64(clearFlagTimeout.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
if clearFlagTime >= time.Now().Unix() {
|
||||||
|
clearFlagTime = -1
|
||||||
|
currentExecState = normalExecutionState
|
||||||
|
setThreadExecStateProc.Call(normalExecutionState)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user