Browse Source

run the mensamenu update task every hour

pull/18/head 1.1.3
Jannik 3 years ago
parent
commit
13a55508d0
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 2
      build.gradle
  2. 36
      src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt
  3. 32
      src/main/kotlin/org/mosad/thecitadelofricks/CacheController.kt

2
build.gradle

@ -38,4 +38,4 @@ compileTestKotlin {
}
group 'org.mosad'
version '1.1.2'
version '1.1.3'

36
src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt

@ -42,7 +42,7 @@ class APIController {
private val logger: Logger = LoggerFactory.getLogger(APIController::class.java)
private val cache = CacheController()
private val softwareVersion = "1.1.2"
private val softwareVersion = "1.1.3"
private val apiVersion = "1.1.1"
private val startTime = System.currentTimeMillis() / 1000
@ -83,9 +83,31 @@ class APIController {
@RequestParam(value = "courseName", defaultValue = "AI4") courseName: String,
@RequestParam(value = "week", defaultValue = "0") week: Int
): HashSet<String> {
val lessonSubjectList = ArrayList<String>()
logger.info("lessonSubjectList request at ${LocalDateTime.now()}!")
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
val flatMap = cache.getTimetable(courseName, week).timetable.days.flatMap { it.timeslots.asIterable() }
@ -96,12 +118,7 @@ class APIController {
return HashSet(lessonSubjectList)
}
@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> {
private fun getLesson(courseName: String, lessonSubject: String, week: Int): ArrayList<Lesson> {
val lessonList = ArrayList<Lesson>()
// get all lessons from the weeks timetable
@ -119,8 +136,7 @@ class APIController {
return lessonList
}
@RequestMapping("/status")
fun status(): Status {
private fun getStatus(): Status {
val currentTime = System.currentTimeMillis() / 1000
val minutes = (currentTime - startTime) % 3600 / 60
val hours = (currentTime - startTime) % 86400 / 3600

32
src/main/kotlin/org/mosad/thecitadelofricks/CacheController.kt

@ -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()
}
}
}
Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close