mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 07:57:55 +02:00
Fixed missing counter reset
This commit is contained in:
@@ -15,7 +15,8 @@ class TaskFactory {
|
|||||||
private val _tasksPerHour: MutableMap<HourAtDay, Int> = mutableMapOf()
|
private val _tasksPerHour: MutableMap<HourAtDay, Int> = mutableMapOf()
|
||||||
|
|
||||||
fun initializeWithExistingTasks(existingTasks: List<ScheduledFetchTask>) {
|
fun initializeWithExistingTasks(existingTasks: List<ScheduledFetchTask>) {
|
||||||
existingTasks.forEach { countTask(it) }
|
resetCounter()
|
||||||
|
countTasks(existingTasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createTaskAndUpdateCounter(eva: Eva, hourAtDay: HourAtDay): ScheduledFetchTask {
|
fun createTaskAndUpdateCounter(eva: Eva, hourAtDay: HourAtDay): ScheduledFetchTask {
|
||||||
@@ -41,6 +42,10 @@ class TaskFactory {
|
|||||||
return hourAtDay.dateTime.plusSeconds(secondInHourToExecute.toLong())
|
return hourAtDay.dateTime.plusSeconds(secondInHourToExecute.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun countTasks(existingTasks: List<ScheduledFetchTask>) {
|
||||||
|
existingTasks.forEach { countTask(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun countTask(scheduledFetchTask: ScheduledFetchTask) {
|
private fun countTask(scheduledFetchTask: ScheduledFetchTask) {
|
||||||
val scheduledTime = scheduledFetchTask.scheduledExecutionDateTime
|
val scheduledTime = scheduledFetchTask.scheduledExecutionDateTime
|
||||||
val hourAtDay = HourAtDay.of(scheduledTime)
|
val hourAtDay = HourAtDay.of(scheduledTime)
|
||||||
@@ -55,4 +60,7 @@ class TaskFactory {
|
|||||||
private fun getNumberOfTasksInHour(hourAtDay: HourAtDay) =
|
private fun getNumberOfTasksInHour(hourAtDay: HourAtDay) =
|
||||||
_tasksPerHour.computeIfAbsent(hourAtDay) { ZERO }
|
_tasksPerHour.computeIfAbsent(hourAtDay) { ZERO }
|
||||||
|
|
||||||
}
|
private fun resetCounter() {
|
||||||
|
_tasksPerHour.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user