1
+ package no.nav.paw.arbeidssoeker.synk.service
2
+
3
+ import no.nav.paw.arbeidssoeker.synk.config.JobConfig
4
+ import no.nav.paw.arbeidssoeker.synk.utils.ArbeidssoekerCsvReader
5
+ import no.nav.paw.logging.logger.buildApplicationLogger
6
+ import no.nav.paw.logging.logger.buildNamedLogger
7
+ import java.io.File
8
+ import java.nio.file.Files
9
+ import java.time.Duration
10
+ import java.time.Instant
11
+ import kotlin.io.path.Path
12
+
13
+ class SyncService (
14
+ private val jobConfig : JobConfig
15
+ ) {
16
+ private val logger = buildApplicationLogger
17
+ private val secureLogger = buildNamedLogger(" secure" )
18
+
19
+ fun syncArbeidssoekere () {
20
+ var count = 0
21
+ val timestamp = Instant .now()
22
+ val file = getFile()
23
+ logger.info(" Leser CSV-fil fra {}" , file.absolutePath)
24
+ val values = ArbeidssoekerCsvReader .readValues(file)
25
+ logger.info(" Starter prosessering av CSV-data" )
26
+ while (values.hasNextValue()) {
27
+ count++
28
+ if (count % 1000 == 0 ) {
29
+ logger.info(" Prosessert {} linjer CSV-data på {} ms" , count, timestamp.millisSince())
30
+ }
31
+ val value = values.nextValue()
32
+ secureLogger.info(" Prosesserer arbeidssøker {}" , value.identitetsnummer)
33
+ }
34
+ logger.info(" Fullførte prosessering av {} linjer CSV-data på {} ms" , count, timestamp.millisSince())
35
+ }
36
+
37
+ private fun getFile (): File {
38
+ with (jobConfig) {
39
+ val path = Path (mountPath)
40
+ if (! Files .exists(path)) {
41
+ throw IllegalStateException (" $mountPath ikke funnet" )
42
+ }
43
+ if (! Files .isRegularFile(path)) {
44
+ throw IllegalStateException (" $mountPath er ikke en fil" )
45
+ }
46
+ if (! Files .isReadable(path)) {
47
+ throw IllegalStateException (" $mountPath kan ikke leses fra" )
48
+ }
49
+ return path.toFile()
50
+ }
51
+ }
52
+
53
+ private fun Instant.millisSince (): Long = Duration .between(this , Instant .now()).toMillis()
54
+ }
0 commit comments