Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasDev committed Jul 19, 2023
1 parent 58ec7c9 commit 889e962
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/main/kotlin/no/nav/syfo/elector/LeadershipHandling.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.syfo.elector

import io.ktor.utils.io.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand All @@ -25,9 +26,17 @@ class LeadershipHandling(
try {
handleLeadership()
delay(5.seconds)
} catch (e: Exception) {
logger.error("Error occurred in leadership handling loop delaying for 10 seconds", e)
delay(10.seconds)
} catch (ex: Exception) {
when (ex) {
is CancellationException -> {
logger.warn("Job was cancelled, message: ${ex.message}")
throw ex
}
else -> {
logger.error("Error occurred in leadership handling loop delaying for 10 seconds", ex)
delay(10.seconds)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class OppgaveClient(
header("X-Correlation-ID", msgId)
}
if (response.status == HttpStatusCode.OK) {
log.info("Hentet oppgave med id $oppgaveId")
return response.body<OpprettOppgaveResponse>()
} else if (response.status == HttpStatusCode.NotFound) {
return null
Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/no/nav/syfo/oppgave/service/UpdateStatusService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.syfo.oppgave.service

import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelAndJoin
Expand Down Expand Up @@ -51,8 +52,16 @@ class UpdateStatusService(
}
jobs.joinAll()
} catch (ex: Exception) {
logger.error("Caught unexpected delaying for 10s $ex")
delay(10.seconds)
when (ex) {
is CancellationException -> {
logger.warn("Job was cancelled, message: ${ex.message}")
throw ex
}
else -> {
logger.error("Caught unexpected delaying for 10s $ex")
delay(10.seconds)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package no.nav.syfo.oppgave.service

import io.kotest.core.spec.style.FunSpec
import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.mockkStatic
import no.nav.syfo.db.DatabaseInterface
import no.nav.syfo.model.ManuellOppgave
import no.nav.syfo.model.Status
import no.nav.syfo.model.ValidationResult
import no.nav.syfo.oppgave.client.OppgaveClient
import no.nav.syfo.persistering.db.opprettManuellOppgave
import no.nav.syfo.testutil.TestDB
import no.nav.syfo.testutil.okApprec
import no.nav.syfo.testutil.receivedSykmelding
import java.util.UUID

class UpdateStatusServiceDbTest : FunSpec({
val database: DatabaseInterface = TestDB.database
val oppgaveClient: OppgaveClient = mockk()
val service: UpdateStatusService = UpdateStatusService(database, oppgaveClient)
mockkStatic("no.nav.syfo.persistering.db.PersisterManuellOppgaveQueriesKt")
coEvery { oppgaveClient.hentOppgave(any(), any()) } returns null
beforeTest {
database.opprettManuellOppgave(
manuellOppgave = ManuellOppgave(
receivedSykmelding = receivedSykmelding(UUID.randomUUID().toString()),
validationResult = ValidationResult(Status.OK, emptyList()),
apprec = okApprec(),
),
okApprec(),
0,
)
}

test("Update status") {
service.start()
}
})

0 comments on commit 889e962

Please sign in to comment.