Browse Source

added initial delay for scheduled updates

pull/18/head
Jannik 3 years ago
parent
commit
cf0327bc88
  1. 2
      build.gradle
  2. 13
      src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt
  3. 1
      src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt
  4. 2
      src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt

2
build.gradle

@ -39,4 +39,4 @@ compileTestKotlin {
}
group 'org.mosad'
version '1.0.1'
version '1.0.2'

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

@ -47,6 +47,7 @@ class APIController {
// Controller stuff
var logger: Logger = LoggerFactory.getLogger(APIController::class.java)
private val startTime = System.currentTimeMillis() / 1000
private val softwareVersion = "1.0.2"
private val apiVersion = "1.0.1"
// hso parser links (hardcoded)
@ -66,19 +67,22 @@ class APIController {
init {
initUpdates() // without this 5-10 seconds after startup the response will be empty
// TODO we could use a first time delay
val currentTime = System.currentTimeMillis()
val delay24h = (86400000 - ((currentTime + 3600000) % 86400000)) + 60000
val delay3h = (10800000 - ((currentTime + 3600000) % 10800000)) + 60000
// update courses every 24 hours (time in ms)
Timer().scheduleAtFixedRate(0, 86400000) {
Timer().scheduleAtFixedRate(delay24h, 86400000) {
asyncUpdateCourses()
}
// update courses every 3 hours (time in ms)
Timer().scheduleAtFixedRate(0, 10800000) {
Timer().scheduleAtFixedRate(delay3h, 10800000) {
asyncUpdateMensa()
}
// update all already existing timetables every 3 hours (time in ms)
Timer().scheduleAtFixedRate(0, 10800000) {
Timer().scheduleAtFixedRate(delay3h, 10800000) {
asyncUpdateTimetables()
}
}
@ -131,6 +135,7 @@ class APIController {
LocalDateTime.now(),
"$days days, $hours:$minutes",
apiVersion,
softwareVersion,
Date(coursesLastUpdate * 1000),
Date(mensaLastUpdate * 1000),
hsoCode,

1
src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt

@ -66,6 +66,7 @@ data class Status(
val time: LocalDateTime,
val uptime: String,
val apiVersion: String,
val softwareVersion: String,
val coursesLastUpdate: Date,
val mensaLastUpdate: Date,
val hsoResponseCode: Int,

2
src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt

@ -61,7 +61,7 @@ class TimetableParser {
// adjust the following slot
sDay++
sLesson = Lesson(
"$day.$rowIndex.$elementIndex",
"$day.$rowIndex.$elementIndex", // FIXME this is broken!
element.select("div.lesson-subject").text(),
element.select("div.lesson-teacher").text(),
element.select("div.lesson-room").text(),

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