mirror of
https://github.com/pcvolkmer/grz-metadata-processor.git
synced 2025-07-01 20:12:54 +00:00
feat: use watch service if no poll delay is set
This commit is contained in:
@ -4,6 +4,7 @@ import dev.pcvolkmer.onco.grzmetadataprocessor.data.File
|
|||||||
import dev.pcvolkmer.onco.grzmetadataprocessor.data.FileRepository
|
import dev.pcvolkmer.onco.grzmetadataprocessor.data.FileRepository
|
||||||
import dev.pcvolkmer.onco.grzmetadataprocessor.data.FileType
|
import dev.pcvolkmer.onco.grzmetadataprocessor.data.FileType
|
||||||
import org.apache.tomcat.util.buf.HexUtils
|
import org.apache.tomcat.util.buf.HexUtils
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
@ -18,13 +19,11 @@ import java.security.DigestInputStream
|
|||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
import kotlin.time.Duration.Companion.minutes
|
|
||||||
import kotlin.time.toJavaDuration
|
|
||||||
|
|
||||||
@ConfigurationProperties(AppSourceFsProperties.NAME)
|
@ConfigurationProperties(AppSourceFsProperties.NAME)
|
||||||
data class AppSourceFsProperties(
|
data class AppSourceFsProperties(
|
||||||
val directory: Path? = null,
|
val directory: Path? = null,
|
||||||
val pollDelay: Duration = 1.minutes.toJavaDuration(),
|
val pollDelay: Duration? = null,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
const val NAME = "app.source.fs"
|
const val NAME = "app.source.fs"
|
||||||
@ -35,6 +34,8 @@ data class AppSourceFsProperties(
|
|||||||
@EnableConfigurationProperties(AppSourceFsProperties::class)
|
@EnableConfigurationProperties(AppSourceFsProperties::class)
|
||||||
class AppIntegrationConfig {
|
class AppIntegrationConfig {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(AppSourceFsProperties::class.java)
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(
|
@ConditionalOnProperty(
|
||||||
name = ["app.source.fs.directory"]
|
name = ["app.source.fs.directory"]
|
||||||
@ -50,7 +51,12 @@ class AppIntegrationConfig {
|
|||||||
return IntegrationFlow
|
return IntegrationFlow
|
||||||
.from(
|
.from(
|
||||||
Files.inboundAdapter(sourceDirectory!!.toFile()).useWatchService(true)
|
Files.inboundAdapter(sourceDirectory!!.toFile()).useWatchService(true)
|
||||||
)
|
) {
|
||||||
|
if (applicationFsProperties.pollDelay != null) {
|
||||||
|
logger.info("Polling new file each ${applicationFsProperties.pollDelay.seconds} seconds...")
|
||||||
|
it.poller(Pollers.fixedDelay(applicationFsProperties.pollDelay))
|
||||||
|
}
|
||||||
|
}
|
||||||
.log()
|
.log()
|
||||||
.handle { msg ->
|
.handle { msg ->
|
||||||
val path = Path(msg.payload.toString())
|
val path = Path(msg.payload.toString())
|
||||||
|
Reference in New Issue
Block a user