run the mensamenu update task every hour
This commit is contained in:
parent
754c8cb17b
commit
13a55508d0
|
@ -38,4 +38,4 @@ compileTestKotlin {
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.mosad'
|
group 'org.mosad'
|
||||||
version '1.1.2'
|
version '1.1.3'
|
||||||
|
|
|
@ -42,7 +42,7 @@ class APIController {
|
||||||
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
|
||||||
private val cache = CacheController()
|
private val cache = CacheController()
|
||||||
|
|
||||||
private val softwareVersion = "1.1.2"
|
private val softwareVersion = "1.1.3"
|
||||||
private val apiVersion = "1.1.1"
|
private val apiVersion = "1.1.1"
|
||||||
private val startTime = System.currentTimeMillis() / 1000
|
private val startTime = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
|
@ -83,9 +83,31 @@ class APIController {
|
||||||
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
||||||
@RequestParam(value = "week", defaultValue = "0") week: Int
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
): HashSet<String> {
|
): HashSet<String> {
|
||||||
val lessonSubjectList = ArrayList<String>()
|
|
||||||
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
|
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
|
||||||
requestCount++
|
requestCount++
|
||||||
|
return getLessonSubjectList(courseName, week)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/lesson")
|
||||||
|
fun lesson(
|
||||||
|
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
||||||
|
@RequestParam(value = "lessonSubject", defaultValue = "Mathematik 4") lessonSubject: String,
|
||||||
|
@RequestParam(value = "week", defaultValue = "0") week: Int
|
||||||
|
): ArrayList<Lesson> {
|
||||||
|
logger.info("lesson request at ${LocalDateTime.now()}!")
|
||||||
|
requestCount++
|
||||||
|
return getLesson(courseName, lessonSubject, week)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/status")
|
||||||
|
fun status(): Status {
|
||||||
|
return getStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
// non direct api functions
|
||||||
|
|
||||||
|
private fun getLessonSubjectList(courseName: String, week: Int): HashSet<String> {
|
||||||
|
val lessonSubjectList = ArrayList<String>()
|
||||||
|
|
||||||
// get every lesson subject for the given week
|
// get every lesson subject for the given week
|
||||||
val flatMap = cache.getTimetable(courseName, week).timetable.days.flatMap { it.timeslots.asIterable() }
|
val flatMap = cache.getTimetable(courseName, week).timetable.days.flatMap { it.timeslots.asIterable() }
|
||||||
|
@ -96,12 +118,7 @@ class APIController {
|
||||||
return HashSet(lessonSubjectList)
|
return HashSet(lessonSubjectList)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/lesson")
|
private fun getLesson(courseName: String, lessonSubject: String, week: Int): ArrayList<Lesson> {
|
||||||
fun lesson(
|
|
||||||
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
|
|
||||||
@RequestParam(value = "lessonSubject", defaultValue = "Mathematik 4") lessonSubject: String,
|
|
||||||
@RequestParam(value = "week", defaultValue = "0") week: Int
|
|
||||||
): ArrayList<Lesson> {
|
|
||||||
val lessonList = ArrayList<Lesson>()
|
val lessonList = ArrayList<Lesson>()
|
||||||
|
|
||||||
// get all lessons from the weeks timetable
|
// get all lessons from the weeks timetable
|
||||||
|
@ -119,8 +136,7 @@ class APIController {
|
||||||
return lessonList
|
return lessonList
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/status")
|
private fun getStatus(): Status {
|
||||||
fun status(): Status {
|
|
||||||
val currentTime = System.currentTimeMillis() / 1000
|
val currentTime = System.currentTimeMillis() / 1000
|
||||||
val minutes = (currentTime - startTime) % 3600 / 60
|
val minutes = (currentTime - startTime) % 3600 / 60
|
||||||
val hours = (currentTime - startTime) % 86400 / 3600
|
val hours = (currentTime - startTime) % 86400 / 3600
|
||||||
|
|
|
@ -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
|
* 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)
|
val result = CourseListParser().getCourseLinks(courseListURL)
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
courseList = CourseList(CourseMeta(System.currentTimeMillis() / 1000, result.size), result)
|
courseList = CourseList(CourseMeta(System.currentTimeMillis() / 1000, result.size), result)
|
||||||
|
@ -155,26 +155,32 @@ class CacheController {
|
||||||
logger.info("init updates successful")
|
logger.info("init updates successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rework!
|
/**
|
||||||
|
* doesn't account the change between winter and summer time!
|
||||||
|
*
|
||||||
|
*/
|
||||||
private fun scheduledUpdates() {
|
private fun scheduledUpdates() {
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
val delay24h = (86400000 - ((currentTime + 3600000) % 86400000)) + 60000
|
val initDelay24h = (86400000 - ((currentTime + 3600000) % 86400000)) + 60000
|
||||||
val delay3h = (10800000 - ((currentTime + 3600000) % 10800000)) + 60000
|
val initDelay3h = (10800000 - ((currentTime + 3600000) % 10800000)) + 60000
|
||||||
|
val initDelay1h = (3600000 - ((currentTime + 3600000) % 10800000)) + 60000
|
||||||
|
|
||||||
// update courses every 24 hours (time in ms)
|
println(initDelay1h / 1000)
|
||||||
Timer().scheduleAtFixedRate(delay24h, 86400000) {
|
|
||||||
asyncUpdateCourses()
|
|
||||||
}
|
|
||||||
|
|
||||||
// update courses every 3 hours (time in ms)
|
// update courseList every 24 hours (time in ms)
|
||||||
Timer().scheduleAtFixedRate(delay3h, 10800000) {
|
Timer().scheduleAtFixedRate(initDelay24h, 86400000) {
|
||||||
asyncUpdateMensa()
|
asyncUpdateCourseList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// update all already existing timetables every 3 hours (time in ms)
|
// update all already existing timetables every 3 hours (time in ms)
|
||||||
Timer().scheduleAtFixedRate(delay3h, 10800000) {
|
Timer().scheduleAtFixedRate(initDelay3h, 10800000) {
|
||||||
asyncUpdateTimetables()
|
asyncUpdateTimetables()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update courses every hour (time in ms)
|
||||||
|
Timer().scheduleAtFixedRate(initDelay1h, 3600000) {
|
||||||
|
asyncUpdateMensa()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue