-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCouchDbChangeDetectionJob.kt
38 lines (32 loc) · 1.2 KB
/
CouchDbChangeDetectionJob.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.aamdigital.aambackendservice.changes.jobs
import com.aamdigital.aambackendservice.changes.core.DatabaseChangeDetection
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.Scheduled
@Configuration
class CouchDbChangeDetectionJob(
private val databaseChangeDetection: DatabaseChangeDetection
) {
private val logger = LoggerFactory.getLogger(javaClass)
companion object {
private var ERROR_COUNTER: Int = 0
private var MAX_ERROR_COUNT: Int = 5
}
@Scheduled(fixedDelay = 8000)
fun checkForCouchDbChanges() {
if (ERROR_COUNTER >= MAX_ERROR_COUNT) {
logger.trace("[CouchDbChangeDetectionJob]: MAX_ERROR_COUNT reached. Not starting job again.")
return
}
try {
databaseChangeDetection.checkForChanges()
} catch (ex: Exception) {
logger.error(
"[CouchDbChangeDetectionJob] An error occurred (count: $ERROR_COUNTER): {}",
ex.localizedMessage
)
logger.debug("[CouchDbChangeDetectionJob] Debug information", ex)
ERROR_COUNTER += 1
}
}
}