From 50ec8982570c25c8876fab993d5acd295def1716 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Thu, 26 Oct 2023 18:55:51 +0200 Subject: [PATCH] Fixed missing counter reset --- .../timetable/bahnApi/model/TaskFactory.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/module-server/src/main/kotlin/de/twomartens/timetable/bahnApi/model/TaskFactory.kt b/module-server/src/main/kotlin/de/twomartens/timetable/bahnApi/model/TaskFactory.kt index 54c7055..e1552f4 100644 --- a/module-server/src/main/kotlin/de/twomartens/timetable/bahnApi/model/TaskFactory.kt +++ b/module-server/src/main/kotlin/de/twomartens/timetable/bahnApi/model/TaskFactory.kt @@ -15,7 +15,8 @@ class TaskFactory { private val _tasksPerHour: MutableMap = mutableMapOf() fun initializeWithExistingTasks(existingTasks: List) { - existingTasks.forEach { countTask(it) } + resetCounter() + countTasks(existingTasks) } fun createTaskAndUpdateCounter(eva: Eva, hourAtDay: HourAtDay): ScheduledFetchTask { @@ -41,6 +42,10 @@ class TaskFactory { return hourAtDay.dateTime.plusSeconds(secondInHourToExecute.toLong()) } + private fun countTasks(existingTasks: List) { + existingTasks.forEach { countTask(it) } + } + private fun countTask(scheduledFetchTask: ScheduledFetchTask) { val scheduledTime = scheduledFetchTask.scheduledExecutionDateTime val hourAtDay = HourAtDay.of(scheduledTime) @@ -55,4 +60,7 @@ class TaskFactory { private fun getNumberOfTasksInHour(hourAtDay: HourAtDay) = _tasksPerHour.computeIfAbsent(hourAtDay) { ZERO } -} \ No newline at end of file + private fun resetCounter() { + _tasksPerHour.clear() + } +}