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