Skip to content

Commit 7024d2d

Browse files
committed
fire and forget for slack og ntfy
1 parent c011d90 commit 7024d2d

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/main/kotlin/no/nav/hjelpemidler/Configuration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal object Configuration {
3838
"HTTP_PORT" to "8085",
3939

4040
"NAIS_APP_NAME" to "hm-oebs-listener",
41-
"NAIS_CLUSTER_NAME" to "local",
41+
"NAIS_CLUSTER_NAME" to Profile.LOCAL.name,
4242
"NAIS_NAMESPACE" to "teamdigihot",
4343

4444
"OEBSTOKEN" to "token",

src/main/kotlin/no/nav/hjelpemidler/Ntfy.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ object Ntfy {
2424
}
2525
}
2626

27-
fun publish(notification: Notification) = runBlocking(Dispatchers.IO) {
28-
val response = client.post(Configuration.ntfyUrl) {
29-
contentType(ContentType.Application.Json)
30-
setBody(notification)
31-
}
32-
when (response.status) {
33-
HttpStatusCode.OK -> Unit
34-
else -> log.warn("Feil ved publisering til ntfy: ${response.body<Map<String, Any?>>()}")
27+
fun publish(notification: Notification) = runCatching {
28+
runBlocking(Dispatchers.IO) {
29+
val response = client.post(Configuration.ntfyUrl) {
30+
contentType(ContentType.Application.Json)
31+
setBody(notification.copy(tags = notification.tags + setOf(Configuration.profile.name)))
32+
}
33+
when (response.status) {
34+
HttpStatusCode.OK -> Unit
35+
else -> log.warn("Feil under publisering til ntfy: ${response.body<Map<String, Any?>>()}")
36+
}
3537
}
38+
}.getOrElse {
39+
log.warn(it) { "Feil under publisering til ntfy" }
3640
}
3741

3842
data class Notification(

src/main/kotlin/no/nav/hjelpemidler/Slack.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object Slack {
2323
}
2424
}
2525

26-
fun post(url: String = Configuration.slackHook, text: String, channel: String) =
26+
fun post(url: String = Configuration.slackHook, text: String, channel: String) = runCatching {
2727
runBlocking(Dispatchers.IO) {
2828
val response = client
2929
.post(url) {
@@ -42,4 +42,7 @@ object Slack {
4242
else -> log.info(response.body<String>())
4343
}
4444
}
45+
}.getOrElse {
46+
log.warn(it) { "Feil under publisering til Slack" }
47+
}
4548
}

src/test/kotlin/no/nav/hjelpemidler/api/OrdreAPITest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ internal class OrdreAPITest {
4747
}
4848
}
4949

50+
@Test
51+
internal fun `sender ut ordrefeilmelding på rapid`() = testApplication {
52+
configure()
53+
val body = context.jsonMapper.writeValueAsString(
54+
Ordrefeilmelding(
55+
id = "1",
56+
saksnummer = "2",
57+
feilmelding = "Feilmelding",
58+
system = "HOTSAK",
59+
status = "ERROR"
60+
)
61+
)
62+
client.post("/ordrefeilmelding") {
63+
bearerAuth("qwer1234")
64+
contentType(ContentType.Application.Json)
65+
setBody(body)
66+
}.apply {
67+
status shouldBe HttpStatusCode.OK
68+
verify {
69+
context.publish("2", match { it.contains(body) })
70+
}
71+
}
72+
}
73+
5074
private fun ApplicationTestBuilder.configure() {
5175
install(ContentNegotiation) {
5276
jackson()

0 commit comments

Comments
 (0)