Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/ha scheduler not triggering missed executions due to not meeting the threshold #612

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions server/src/main/kotlin/suwayomi/tachidesk/util/HAScheduler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,8 @@ object HAScheduler {
if (systemWasInHibernation) {
logger.debug { "System hibernation detected, task was delayed by ${elapsedTime - interval.inWholeMilliseconds}ms" }
scheduledTasks.forEach {
val missedExecution = currentTime - it.getLastExecutionTime() - elapsedTime < 0
val taskInterval = it.getNextExecutionTime() - it.getLastExecutionTime()
// in case the next task execution doesn't take long the missed execution can be ignored to prevent a double execution
val taskThresholdMet = taskInterval * TASK_THRESHOLD > it.getTimeToNextExecution()

val triggerTask = missedExecution && taskThresholdMet
if (triggerTask) {
val wasLastExecutionMissed = currentTime - it.getLastExecutionTime() - elapsedTime < 0
if (wasLastExecutionMissed) {
logger.debug { "Task \"${it.name ?: it.id}\" missed its execution, executing now..." }

when (it) {
Expand All @@ -121,7 +116,7 @@ object HAScheduler {
}

// queue is ordered by next execution time, thus, loop can be exited early
if (!missedExecution) {
if (!wasLastExecutionMissed) {
return@forEach
}
}
Expand Down