-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-1739: Resende 64 meldinger til Arena (#224)
- Loading branch information
1 parent
cb85654
commit dbb2760
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/no/nav/syfo/application/SendDialogmeldingArenaAdhocCronjob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package no.nav.syfo.application | ||
|
||
import net.logstash.logback.argument.StructuredArguments | ||
import no.nav.syfo.application.cronjob.Cronjob | ||
import no.nav.syfo.application.cronjob.CronjobResult | ||
import no.nav.syfo.db.DatabaseInterface | ||
import no.nav.syfo.model.ReceivedDialogmelding | ||
import no.nav.syfo.persistering.db.getAdhocArenaMeldinger | ||
import no.nav.syfo.persistering.db.lagreSendtArena | ||
import no.nav.syfo.services.ArenaDialogmeldingService | ||
import no.nav.syfo.util.safeUnmarshal | ||
import org.slf4j.LoggerFactory | ||
|
||
class SendDialogmeldingArenaAdhocCronjob( | ||
private val database: DatabaseInterface, | ||
private val arenaDialogmeldingService: ArenaDialogmeldingService, | ||
) : Cronjob { | ||
override val initialDelayMinutes: Long = 3 | ||
override val intervalDelayMinutes: Long = 1000 | ||
|
||
override suspend fun run() { | ||
val result = runJob() | ||
log.info( | ||
"Completed sending dialogmelding from adhoc list to arena with result: {}, {}", | ||
StructuredArguments.keyValue("failed", result.failed), | ||
StructuredArguments.keyValue("updated", result.updated), | ||
) | ||
} | ||
|
||
suspend fun runJob(): CronjobResult { | ||
val result = CronjobResult() | ||
val adhocArenaMeldinger = database.getAdhocArenaMeldinger() | ||
adhocArenaMeldinger.forEach { (dialogmeldingId, fellesformat, msgId) -> | ||
try { | ||
val fellesformatXml = safeUnmarshal(fellesformat) | ||
val receivedDialogmelding = ReceivedDialogmelding.create( | ||
dialogmeldingId = dialogmeldingId, | ||
fellesformat = fellesformatXml, | ||
inputMessageText = fellesformat, | ||
) | ||
arenaDialogmeldingService.sendArenaDialogmeldingToMQ( | ||
receivedDialogmelding = receivedDialogmelding, | ||
fellesformatXml = fellesformatXml | ||
) | ||
database.lagreSendtArena( | ||
dialogmeldingid = dialogmeldingId, | ||
isSent = true, | ||
) | ||
result.updated++ | ||
} catch (e: Exception) { | ||
log.error("Caught exception in ad hoc sending dialogmelding to arena", e) | ||
result.failed++ | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
companion object { | ||
private val log = LoggerFactory.getLogger(SendDialogmeldingArenaAdhocCronjob::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters