Allowing continue
This commit is contained in:
parent
8a042a3fd3
commit
c39366960f
@ -1,11 +1,13 @@
|
||||
package no.iktdev.mediaprocessing.coordinator.controller
|
||||
|
||||
import no.iktdev.mediaprocessing.coordinator.dto.translate.ApiResponse
|
||||
import no.iktdev.mediaprocessing.coordinator.services.SequenceAggregatorService
|
||||
import no.iktdev.mediaprocessing.shared.common.dto.SequenceSummary
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import no.iktdev.mediaprocessing.shared.database.stores.EventStore
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import java.util.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sequences")
|
||||
@ -24,4 +26,32 @@ class SequenceController(
|
||||
): List<SequenceSummary> {
|
||||
return aggregator.getRecentSequences(limit)
|
||||
}
|
||||
|
||||
@PostMapping("/{referenceId}/continue")
|
||||
fun continueSequence(
|
||||
@PathVariable referenceId: UUID
|
||||
): ResponseEntity<ApiResponse> {
|
||||
return try {
|
||||
|
||||
val id = EventStore.createManuallyContinueEvent(referenceId)
|
||||
|
||||
ResponseEntity.ok(
|
||||
ApiResponse(
|
||||
ok = true,
|
||||
message = "Sequence continued, event $id created!"
|
||||
)
|
||||
)
|
||||
|
||||
} catch (ex: Exception) {
|
||||
ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(
|
||||
ApiResponse(
|
||||
ok = false,
|
||||
message = ex.message ?: "Unknown error"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package no.iktdev.mediaprocessing.coordinator.dto.translate
|
||||
|
||||
data class ApiResponse(
|
||||
val ok: Boolean,
|
||||
val message: String
|
||||
)
|
||||
@ -52,7 +52,7 @@ class EventService {
|
||||
}
|
||||
|
||||
fun createForcedTaskResetAuditEvent(referenceId: UUID, taskId: UUID): UUID? {
|
||||
return EventStore.createTaskResetAudioEvent(referenceId, taskId)
|
||||
return EventStore.createTaskResetAuditEvent(referenceId, taskId)
|
||||
}
|
||||
|
||||
fun getEffectiveHistory(referenceId: UUID): List<PersistedEvent> {
|
||||
|
||||
@ -12,6 +12,7 @@ import no.iktdev.mediaprocessing.shared.common.dto.Paginated
|
||||
import no.iktdev.mediaprocessing.shared.common.event_task_contract.events.CompletedEvent
|
||||
import no.iktdev.mediaprocessing.shared.common.event_task_contract.events.DeletedTaskResultEvent
|
||||
import no.iktdev.mediaprocessing.shared.common.event_task_contract.events.ForcedTaskResetAuditEvent
|
||||
import no.iktdev.mediaprocessing.shared.common.event_task_contract.events.ManualAllowCompletionEvent
|
||||
import no.iktdev.mediaprocessing.shared.common.getName
|
||||
import no.iktdev.mediaprocessing.shared.database.likeAny
|
||||
import no.iktdev.mediaprocessing.shared.database.queries.pagedQuery
|
||||
@ -126,13 +127,26 @@ object EventStore: EventStore {
|
||||
return null
|
||||
}
|
||||
|
||||
fun createTaskResetAudioEvent(referenceId: UUID, taskId: UUID): UUID {
|
||||
fun createTaskResetAuditEvent(referenceId: UUID, taskId: UUID): UUID {
|
||||
val auditEvent = ForcedTaskResetAuditEvent(taskId)
|
||||
.usingReferenceId(referenceId)
|
||||
persist(auditEvent)
|
||||
return auditEvent.eventId
|
||||
}
|
||||
|
||||
fun createManuallyContinueEvent(referenceId: UUID): UUID? {
|
||||
return try {
|
||||
val continueEvent = ManualAllowCompletionEvent().apply {
|
||||
usingReferenceId(referenceId)
|
||||
}
|
||||
persist(continueEvent)
|
||||
return continueEvent.eventId
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun eventsLast(minutes: Long = 1): Long {
|
||||
val cutoff = Instant.now().minus(minutes, ChronoUnit.MINUTES)
|
||||
return withTransaction {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user