don't use lateinit in CacheController()
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f01916b363
commit
3aa27dff4a
|
@ -60,12 +60,12 @@ class APIController {
|
||||||
// TODO remove this with API version 2.0.0
|
// TODO remove this with API version 2.0.0
|
||||||
@Deprecated("courses is replaced by courseList", replaceWith = ReplaceWith("courseList()"))
|
@Deprecated("courses is replaced by courseList", replaceWith = ReplaceWith("courseList()"))
|
||||||
@RequestMapping("/courses")
|
@RequestMapping("/courses")
|
||||||
fun courses(): CourseList {
|
fun courses(): CoursesList {
|
||||||
return courseList()
|
return courseList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/courseList")
|
@RequestMapping("/courseList")
|
||||||
fun courseList(): CourseList {
|
fun courseList(): CoursesList {
|
||||||
logger.info("courseList request at ${LocalDateTime.now()}!")
|
logger.info("courseList request at ${LocalDateTime.now()}!")
|
||||||
updateTotalRequests()
|
updateTotalRequests()
|
||||||
return courseList
|
return courseList
|
||||||
|
|
|
@ -28,9 +28,9 @@ import java.util.*
|
||||||
// data classes for the course part
|
// data classes for the course part
|
||||||
data class Course(val courseName: String, val courseLink: String)
|
data class Course(val courseName: String, val courseLink: String)
|
||||||
|
|
||||||
data class CourseMeta(val updateTime: Long, val totalCourses: Int)
|
data class CoursesMeta(val updateTime: Long, val totalCourses: Int)
|
||||||
|
|
||||||
data class CourseList(val meta: CourseMeta, val courses: ArrayList<Course>)
|
data class CoursesList(val meta: CoursesMeta, val courses: ArrayList<Course>)
|
||||||
|
|
||||||
// data classes for the Mensa part
|
// data classes for the Mensa part
|
||||||
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
||||||
|
|
|
@ -55,8 +55,8 @@ class CacheController {
|
||||||
companion object{
|
companion object{
|
||||||
private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java)
|
private val logger: Logger = LoggerFactory.getLogger(CacheController::class.java)
|
||||||
|
|
||||||
lateinit var courseList: CourseList
|
var courseList = CoursesList(CoursesMeta(0, 0), ArrayList())
|
||||||
lateinit var mensaMenu: MensaMenu
|
var mensaMenu = MensaMenu(MensaMeta(0,""), MensaWeek(), MensaWeek())
|
||||||
var timetableList = ArrayList<TimetableCourseWeek>() // this list contains all timetables
|
var timetableList = ArrayList<TimetableCourseWeek>() // this list contains all timetables
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,12 +141,12 @@ class CacheController {
|
||||||
*/
|
*/
|
||||||
private fun asyncUpdateCourseList() = GlobalScope.launch {
|
private fun asyncUpdateCourseList() = GlobalScope.launch {
|
||||||
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
||||||
courseList = CourseList(
|
courseList = CoursesList(
|
||||||
CourseMeta(System.currentTimeMillis() / 1000, it.size), it
|
CoursesMeta(System.currentTimeMillis() / 1000, it.size), it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("updated courses successful at ${Date(courseList.meta.updateTime * 1000)}")
|
logger.info("Updated courses successful at ${Date(courseList.meta.updateTime * 1000)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,7 +164,7 @@ class CacheController {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("updated mensamenu successful at ${Date(mensaMenu.meta.updateTime * 1000)}")
|
logger.info("Updated mensamenu successful at ${Date(mensaMenu.meta.updateTime * 1000)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,7 +173,7 @@ class CacheController {
|
||||||
* a FixedThreadPool is used to make parallel requests for faster updates
|
* a FixedThreadPool is used to make parallel requests for faster updates
|
||||||
*/
|
*/
|
||||||
private fun asyncUpdateTimetables() = GlobalScope.launch {
|
private fun asyncUpdateTimetables() = GlobalScope.launch {
|
||||||
logger.info("updating ${timetableList.size} timetables ...")
|
logger.info("Updating ${timetableList.size} timetables ...")
|
||||||
|
|
||||||
// create a new ThreadPool with 5 threads
|
// create a new ThreadPool with 5 threads
|
||||||
val executor = Executors.newFixedThreadPool(5)
|
val executor = Executors.newFixedThreadPool(5)
|
||||||
|
@ -189,7 +189,7 @@ class CacheController {
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
logger.error("error while updating the timetables", ex)
|
logger.error("Error while updating the timetables", ex)
|
||||||
} finally {
|
} finally {
|
||||||
executor.shutdown()
|
executor.shutdown()
|
||||||
}
|
}
|
||||||
|
@ -214,16 +214,16 @@ class CacheController {
|
||||||
* runBlocking: otherwise the api would return no data to requests for a few seconds after startup
|
* runBlocking: otherwise the api would return no data to requests for a few seconds after startup
|
||||||
*/
|
*/
|
||||||
private fun initUpdates() = runBlocking {
|
private fun initUpdates() = runBlocking {
|
||||||
// get all courses on startup
|
// get all course links on startup, make sure there are course links
|
||||||
val jobCourseUpdate = GlobalScope.async {
|
val jobCourseUpdate = GlobalScope.async {
|
||||||
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
CourseListParser().getCourseLinks(StartupController.courseListURL)?.let {
|
||||||
courseList = CourseList(
|
courseList = CoursesList(
|
||||||
CourseMeta(System.currentTimeMillis() / 1000, it.size), it
|
CoursesMeta(System.currentTimeMillis() / 1000, it.size), it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the current and next weeks mensa menus
|
// get the current and next weeks mensa menu
|
||||||
val jobMensa = GlobalScope.async{
|
val jobMensa = GlobalScope.async{
|
||||||
val mensaCurrentWeek = MensaParser().getMensaMenu(StartupController.mensaMenuURL)
|
val mensaCurrentWeek = MensaParser().getMensaMenu(StartupController.mensaMenuURL)
|
||||||
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(StartupController.mensaMenuURL))
|
val mensaNextWeek = MensaParser().getMensaMenu(MensaParser().getMenuLinkNextWeek(StartupController.mensaMenuURL))
|
||||||
|
@ -239,7 +239,7 @@ class CacheController {
|
||||||
jobCourseUpdate.await()
|
jobCourseUpdate.await()
|
||||||
jobMensa.await()
|
jobMensa.await()
|
||||||
|
|
||||||
logger.info("init updates successful")
|
logger.info("Initial updates successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue