run the mensamenu update task every hour

This commit is contained in:
2019-06-02 16:55:36 +02:00
parent 754c8cb17b
commit 13a55508d0
3 changed files with 46 additions and 24 deletions

View File

@ -84,10 +84,10 @@ class CacheController {
}
/**
* this function updates the courses list
* this function updates the courseList
* during the update process the old data will be returned for a API request
*/
private fun asyncUpdateCourses() = GlobalScope.launch {
private fun asyncUpdateCourseList() = GlobalScope.launch {
val result = CourseListParser().getCourseLinks(courseListURL)
if (result != null) {
courseList = CourseList(CourseMeta(System.currentTimeMillis() / 1000, result.size), result)
@ -155,26 +155,32 @@ class CacheController {
logger.info("init updates successful")
}
// TODO rework!
/**
* doesn't account the change between winter and summer time!
*
*/
private fun scheduledUpdates() {
val currentTime = System.currentTimeMillis()
val delay24h = (86400000 - ((currentTime + 3600000) % 86400000)) + 60000
val delay3h = (10800000 - ((currentTime + 3600000) % 10800000)) + 60000
val initDelay24h = (86400000 - ((currentTime + 3600000) % 86400000)) + 60000
val initDelay3h = (10800000 - ((currentTime + 3600000) % 10800000)) + 60000
val initDelay1h = (3600000 - ((currentTime + 3600000) % 10800000)) + 60000
// update courses every 24 hours (time in ms)
Timer().scheduleAtFixedRate(delay24h, 86400000) {
asyncUpdateCourses()
}
println(initDelay1h / 1000)
// update courses every 3 hours (time in ms)
Timer().scheduleAtFixedRate(delay3h, 10800000) {
asyncUpdateMensa()
// update courseList every 24 hours (time in ms)
Timer().scheduleAtFixedRate(initDelay24h, 86400000) {
asyncUpdateCourseList()
}
// update all already existing timetables every 3 hours (time in ms)
Timer().scheduleAtFixedRate(delay3h, 10800000) {
Timer().scheduleAtFixedRate(initDelay3h, 10800000) {
asyncUpdateTimetables()
}
// update courses every hour (time in ms)
Timer().scheduleAtFixedRate(initDelay1h, 3600000) {
asyncUpdateMensa()
}
}
}