Skip to content

Commit

Permalink
rest for download started; swagger (#99)
Browse files Browse the repository at this point in the history
* rest for download started; swagger

* older swagger

* 2.10
  • Loading branch information
dpozinen authored Jan 20, 2024
1 parent 9aae03a commit b844cd1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'dpozinen'
version = '2.9'
version = '2.10'

repositories {
mavenCentral()
Expand All @@ -29,6 +29,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.0.4'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'io.github.openfeign:feign-jackson:12.5'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

implementation 'javax.xml.bind:jaxb-api:2.3.1'

Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/dpozinen/deluge/core/SonarrCallbacks.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dpozinen.deluge.core

import dpozinen.deluge.domain.DownloadSonarrEvent
import dpozinen.deluge.domain.GrabSonarrEvent
import dpozinen.deluge.rest.DelugeRequest
import dpozinen.deluge.rest.clients.DelugeActionsClient
import mu.KotlinLogging.logger
Expand All @@ -18,7 +17,7 @@ class SonarrCallbacks(
) {
private val log = logger {}

fun downloadStarted(event: GrabSonarrEvent) {
fun downloadStarted() {
delugeService.followDownloading()
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/dpozinen/deluge/core/StatUpdateJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlin.time.Duration
@ConditionalOnProperty("tracker-ops.deluge.stats.enabled", havingValue = "true", matchIfMissing = true)
open class StatUpdateJob(
private val delugeStatsService: DelugeStatsService,
private val delugeService: DelugeService,
@Value("\${tracker-ops.deluge.stats.poll-interval}") private val interval: String
) {
private val log = KotlinLogging.logger { }
Expand All @@ -23,10 +24,12 @@ open class StatUpdateJob(
fun startJob() {
GlobalScope.launch(Dispatchers.IO) {
while (true) {
runCatching { delugeStatsService.collectStats() }
.onFailure {
log.error { it }
}
runCatching {
delugeStatsService.collectStats()
delugeService.followDownloading()
}.onFailure {
log.error { it }
}
delay(Duration.parse(interval))
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/dpozinen/deluge/rest/CallbacksController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class CallbacksController(
)
}

@GetMapping("/api/callbacks/download-started")
fun follow() {
sonarrCallbacks.downloadStarted()
}

@GetMapping("/api/callbacks/true-nas-move")
fun trueNasMove() {
downloadedCallbacks.trueNasMove()
Expand All @@ -37,7 +42,7 @@ class CallbacksController(
fun sonarr(@RequestBody event: SonarrEvent) {
log.info { jacksonObjectMapper().writeValueAsString(event) }
when (event) {
is GrabSonarrEvent -> sonarrCallbacks.downloadStarted(event)
is GrabSonarrEvent -> sonarrCallbacks.downloadStarted()
is DownloadSonarrEvent -> sonarrCallbacks.downloadCompleted(event)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/deluge/CallbacksControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CallbacksControllerTest(
}
}

verify { sonarrCallbacks.downloadStarted(any()) }
verify { sonarrCallbacks.downloadStarted() }
}

@Test
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/deluge/SonarrCallbacksTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import dpozinen.deluge.core.DelugeService
import dpozinen.deluge.core.SonarrCallbacks
import dpozinen.deluge.domain.DownloadSonarrEvent
import dpozinen.deluge.domain.EpisodeFile
import dpozinen.deluge.domain.GrabSonarrEvent
import dpozinen.deluge.domain.Series
import dpozinen.deluge.rest.DelugeRequest
import dpozinen.deluge.rest.DelugeRequest.Method.move_storage
Expand Down Expand Up @@ -42,7 +41,7 @@ class SonarrCallbacksTest {

@Test
fun `should trigger follow on download started event`() {
sonarrCallbacks.downloadStarted(GrabSonarrEvent(Series("")))
sonarrCallbacks.downloadStarted()

verify { delugeService.followDownloading() }
}
Expand Down

0 comments on commit b844cd1

Please sign in to comment.