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.asWatchChannel
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mu.KotlinLogging
|
||||
import no.iktdev.mediaprocessing.coordinator.*
|
||||
import no.iktdev.mediaprocessing.shared.common.SharedConfig
|
||||
import no.iktdev.mediaprocessing.shared.common.extended.isSupportedVideoFile
|
||||
import no.iktdev.mediaprocessing.shared.contract.ProcessType
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.stereotype.Service
|
||||
import java.io.File
|
||||
import javax.annotation.PreDestroy
|
||||
|
||||
|
||||
interface FileWatcherEvents {
|
||||
@ -35,13 +39,19 @@ interface FileWatcherEvents {
|
||||
|
||||
@Service
|
||||
class InputDirectoryWatcher(@Autowired var coordinator: Coordinator): FileWatcherEvents {
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
val watcherChannel = SharedConfig.incomingContent.asWatchChannel()
|
||||
val queue = FileWatcherQueue()
|
||||
|
||||
private var isStopping: Boolean = false
|
||||
@PreDestroy
|
||||
fun setStop() {
|
||||
isStopping = true
|
||||
}
|
||||
|
||||
init {
|
||||
ioCoroutine.launch {
|
||||
|
||||
suspend fun watchFiles() {
|
||||
log.info { "Starting Watcher" }
|
||||
watcherChannel.consumeEach {
|
||||
if (it.file == SharedConfig.incomingContent) {
|
||||
@ -64,9 +74,21 @@ class InputDirectoryWatcher(@Autowired var coordinator: Coordinator): FileWatche
|
||||
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 {
|
||||
return if (file.isFile && file.isSupportedVideoFile()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user