@@ -23,44 +23,48 @@ import kotlin.system.exitProcess
23
23
fun main () {
24
24
val logger = buildApplicationLogger
25
25
26
- try {
27
- logger.info(" Initialiserer jobb" )
26
+ val jobConfig = loadNaisOrLocalConfiguration<JobConfig >(JOB_CONFIG )
27
+ val databaseConfig = loadNaisOrLocalConfiguration<DatabaseConfig >(DATABASE_CONFIG )
28
+ val azureAdM2MConfig = loadNaisOrLocalConfiguration<AzureAdM2MConfig >(AZURE_M2M_CONFIG )
28
29
29
- val jobConfig = loadNaisOrLocalConfiguration<JobConfig >(JOB_CONFIG )
30
- val databaseConfig = loadNaisOrLocalConfiguration<DatabaseConfig >(DATABASE_CONFIG )
31
- val azureAdM2MConfig = loadNaisOrLocalConfiguration<AzureAdM2MConfig >(AZURE_M2M_CONFIG )
30
+ with (jobConfig) {
31
+ if (jobEnabled) {
32
+ try {
33
+ logger.info(" Initialiserer jobb" )
32
34
33
- with (jobConfig) {
34
- val arbeidssoekerSynkRepository = ArbeidssoekerSynkRepository ()
35
- val azureAdM2MTokenClient = createAzureAdM2MTokenClient(runtimeEnvironment, azureAdM2MConfig)
36
- val inngangHttpConsumer = InngangHttpConsumer (apiInngang.baseUrl) {
37
- azureAdM2MTokenClient.createMachineToMachineToken(apiInngang.scope)
38
- }
39
- val arbeidssoekerSynkService =
40
- ArbeidssoekerSynkService (jobConfig, arbeidssoekerSynkRepository, inngangHttpConsumer)
35
+ val arbeidssoekerSynkRepository = ArbeidssoekerSynkRepository ()
36
+ val azureAdM2MTokenClient = createAzureAdM2MTokenClient(runtimeEnvironment, azureAdM2MConfig)
37
+ val inngangHttpConsumer = InngangHttpConsumer (apiInngang.baseUrl) {
38
+ azureAdM2MTokenClient.createMachineToMachineToken(apiInngang.scope)
39
+ }
40
+ val arbeidssoekerSynkService =
41
+ ArbeidssoekerSynkService (jobConfig, arbeidssoekerSynkRepository, inngangHttpConsumer)
41
42
42
- logger.info(" Starter jobb" )
43
+ logger.info(" Starter jobb" )
43
44
44
- val filePath = Paths .get(syncFilePath)
45
- logger.info(" Leser CSV-fil {} fra mappe {}" , filePath.name, filePath.parent)
45
+ val filePath = Paths .get(syncFilePath)
46
+ logger.info(" Leser CSV-fil {} fra mappe {}" , filePath.name, filePath.parent)
46
47
47
- val rows = ArbeidssoekerCsvReader .readValues(filePath)
48
- if (rows.hasNextValue()) {
49
- val dataSource = createHikariDataSource(databaseConfig)
50
- dataSource.flywayMigrate()
51
- Database .connect(dataSource)
48
+ val rows = ArbeidssoekerCsvReader .readValues(filePath)
49
+ if (rows.hasNextValue()) {
50
+ val dataSource = createHikariDataSource(databaseConfig)
51
+ dataSource.flywayMigrate()
52
+ Database .connect(dataSource)
52
53
53
- arbeidssoekerSynkService.synkArbeidssoekere(filePath.name, rows)
54
- } else {
55
- logger.warn(" CSV-fil {} fra mappe {} er tom" , filePath.name, filePath.parent)
56
- }
54
+ arbeidssoekerSynkService.synkArbeidssoekere(filePath.name, rows)
55
+ } else {
56
+ logger.warn(" CSV-fil {} fra mappe {} er tom" , filePath.name, filePath.parent)
57
+ }
57
58
58
- exitProcess(0 )
59
+ exitProcess(0 )
60
+ } catch (throwable: Throwable ) {
61
+ logger.error(" Kjøring feilet" , throwable)
62
+ exitProcess(1 )
63
+ } finally {
64
+ logger.info(" Avslutter jobb" )
65
+ }
66
+ } else {
67
+ logger.info(" Jobb er inaktivert" )
59
68
}
60
- } catch (throwable: Throwable ) {
61
- logger.error(" Kjøring feilet" , throwable)
62
- exitProcess(1 )
63
- } finally {
64
- logger.info(" Avslutter jobb" )
65
69
}
66
70
}
0 commit comments