mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 07:57:55 +02:00
change: Don't embed timetable in another document
This commit is contained in:
+7
-6
@@ -1,7 +1,7 @@
|
||||
package de.twomartens.timetable.service
|
||||
|
||||
import de.twomartens.timetable.model.db.Timetable
|
||||
import de.twomartens.timetable.model.dto.TimetableState
|
||||
import de.twomartens.timetable.timetable.TimetableRepository
|
||||
import mu.KotlinLogging
|
||||
import org.springframework.batch.core.Job
|
||||
import org.springframework.batch.core.JobParametersBuilder
|
||||
@@ -14,7 +14,7 @@ import org.springframework.scheduling.annotation.Async
|
||||
class ProcessTimetableTask(
|
||||
private val asyncJobLauncher: JobLauncher,
|
||||
private val processTimetableJob: Job,
|
||||
private val tswTimetable: Timetable,
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val repository: ScheduledProcessTimetableTaskRepository,
|
||||
private val scheduledTask: ScheduledProcessTimetableTask) : Runnable {
|
||||
|
||||
@@ -24,14 +24,15 @@ class ProcessTimetableTask(
|
||||
}
|
||||
|
||||
fun processTimetable() {
|
||||
if (tswTimetable.timetableState != TimetableState.TIMETABLES_FETCHED) {
|
||||
log.info("Timetable ${tswTimetable.timetableId} is not in TIMETABLES_FETCHED state")
|
||||
val timetable = timetableRepository.findByUserIdAndTimetableId(scheduledTask.userId, scheduledTask.timetableId)!!
|
||||
if (timetable.timetableState != TimetableState.TIMETABLES_FETCHED) {
|
||||
log.info("Timetable ${scheduledTask.timetableId} is not in TIMETABLES_FETCHED state")
|
||||
return
|
||||
}
|
||||
|
||||
val jobParameters = JobParametersBuilder()
|
||||
.addString("timetableId", tswTimetable.timetableId.value)
|
||||
.addString("userId", tswTimetable.userId.value)
|
||||
.addString("timetableId", scheduledTask.timetableId.value)
|
||||
.addString("userId", scheduledTask.userId.value)
|
||||
.toJobParameters()
|
||||
|
||||
try {
|
||||
|
||||
-2
@@ -2,7 +2,6 @@ package de.twomartens.timetable.service
|
||||
|
||||
import de.twomartens.timetable.model.common.TimetableId
|
||||
import de.twomartens.timetable.model.common.UserId
|
||||
import de.twomartens.timetable.model.db.Timetable
|
||||
import org.bson.types.ObjectId
|
||||
import org.springframework.data.annotation.CreatedDate
|
||||
import org.springframework.data.annotation.Id
|
||||
@@ -16,7 +15,6 @@ import java.time.Instant
|
||||
data class ScheduledProcessTimetableTask(
|
||||
var userId: UserId,
|
||||
var timetableId: TimetableId,
|
||||
var timetable: Timetable,
|
||||
var executionTime: Instant
|
||||
) {
|
||||
@Id
|
||||
|
||||
+5
-3
@@ -1,6 +1,7 @@
|
||||
package de.twomartens.timetable.service
|
||||
|
||||
import de.twomartens.timetable.model.db.Timetable
|
||||
import de.twomartens.timetable.timetable.TimetableRepository
|
||||
import org.springframework.batch.core.Job
|
||||
import org.springframework.batch.core.launch.JobLauncher
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent
|
||||
@@ -16,6 +17,7 @@ class TimetableProcessingScheduler(
|
||||
private val asyncJobLauncher: JobLauncher,
|
||||
private val threadPoolTaskScheduler: ThreadPoolTaskScheduler,
|
||||
private val repository: ScheduledProcessTimetableTaskRepository,
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val clock: Clock,
|
||||
private val eventPublisher: ApplicationEventPublisher
|
||||
) {
|
||||
@@ -24,7 +26,7 @@ class TimetableProcessingScheduler(
|
||||
val tasks = repository.findScheduledProcessTimetableTasksByExecutionTimeAfter(clock.instant())
|
||||
tasks.forEach {
|
||||
val task = ProcessTimetableTask(asyncJobLauncher, processTimetableJob,
|
||||
it.timetable, repository, it)
|
||||
timetableRepository, repository, it)
|
||||
threadPoolTaskScheduler.schedule(task, it.executionTime)
|
||||
}
|
||||
}
|
||||
@@ -33,13 +35,13 @@ class TimetableProcessingScheduler(
|
||||
fun onProcessTimetableTaskScheduled(event: ProcessTimetableTaskScheduledEvent) {
|
||||
val source = event.source as ScheduledProcessTimetableTask
|
||||
val task = ProcessTimetableTask(asyncJobLauncher, processTimetableJob,
|
||||
source.timetable, repository, source)
|
||||
timetableRepository, repository, source)
|
||||
threadPoolTaskScheduler.schedule(task, source.executionTime)
|
||||
}
|
||||
|
||||
fun scheduleTimetableProcessing(timetable: Timetable) {
|
||||
val task = ScheduledProcessTimetableTask(timetable.userId, timetable.timetableId,
|
||||
timetable, timetable.fetchDate.plusDays(2)
|
||||
timetable.fetchDate.plusDays(2)
|
||||
.atStartOfDay(clock.zone).toInstant())
|
||||
repository.save(task)
|
||||
val event = ProcessTimetableTaskScheduledEvent(task)
|
||||
|
||||
Reference in New Issue
Block a user