v3 31 - Restart watcher
This commit is contained in:
parent
f5a3603a5a
commit
0aee64c7f3
@ -4,14 +4,18 @@ import dev.vishna.watchservice.KWatchEvent.Kind.Deleted
|
|||||||
import dev.vishna.watchservice.KWatchEvent.Kind.Initialized
|
import dev.vishna.watchservice.KWatchEvent.Kind.Initialized
|
||||||
import dev.vishna.watchservice.asWatchChannel
|
import dev.vishna.watchservice.asWatchChannel
|
||||||
import kotlinx.coroutines.channels.consumeEach
|
import kotlinx.coroutines.channels.consumeEach
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import no.iktdev.mediaprocessing.coordinator.*
|
import no.iktdev.mediaprocessing.coordinator.*
|
||||||
import no.iktdev.mediaprocessing.shared.common.SharedConfig
|
import no.iktdev.mediaprocessing.shared.common.SharedConfig
|
||||||
import no.iktdev.mediaprocessing.shared.common.extended.isSupportedVideoFile
|
import no.iktdev.mediaprocessing.shared.common.extended.isSupportedVideoFile
|
||||||
import no.iktdev.mediaprocessing.shared.contract.ProcessType
|
import no.iktdev.mediaprocessing.shared.contract.ProcessType
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import javax.annotation.PreDestroy
|
||||||
|
|
||||||
|
|
||||||
interface FileWatcherEvents {
|
interface FileWatcherEvents {
|
||||||
@ -35,13 +39,19 @@ interface FileWatcherEvents {
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
class InputDirectoryWatcher(@Autowired var coordinator: Coordinator): FileWatcherEvents {
|
class InputDirectoryWatcher(@Autowired var coordinator: Coordinator): FileWatcherEvents {
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
val watcherChannel = SharedConfig.incomingContent.asWatchChannel()
|
val watcherChannel = SharedConfig.incomingContent.asWatchChannel()
|
||||||
val queue = FileWatcherQueue()
|
val queue = FileWatcherQueue()
|
||||||
|
|
||||||
|
private var isStopping: Boolean = false
|
||||||
|
@PreDestroy
|
||||||
|
fun setStop() {
|
||||||
|
isStopping = true
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
ioCoroutine.launch {
|
suspend fun watchFiles() {
|
||||||
log.info { "Starting Watcher" }
|
log.info { "Starting Watcher" }
|
||||||
watcherChannel.consumeEach {
|
watcherChannel.consumeEach {
|
||||||
if (it.file == SharedConfig.incomingContent) {
|
if (it.file == SharedConfig.incomingContent) {
|
||||||
@ -64,9 +74,21 @@ class InputDirectoryWatcher(@Autowired var coordinator: Coordinator): FileWatche
|
|||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info { "Reached end of watcherChannel" }
|
log.warn { "Watcher stopped!!!" }
|
||||||
|
if (!isStopping) {
|
||||||
|
ioCoroutine.launch {
|
||||||
|
watchFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
ioCoroutine.launch {
|
||||||
|
watchFiles()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun addFile(file: File): Boolean {
|
private fun addFile(file: File): Boolean {
|
||||||
return if (file.isFile && file.isSupportedVideoFile()) {
|
return if (file.isFile && file.isSupportedVideoFile()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user