بنقرة واحدة
slack-alerting
SlackService feilakkumulering og Tags-basert varsling for prosesseringsfeil i SKE-batch
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
SlackService feilakkumulering og Tags-basert varsling for prosesseringsfeil i SKE-batch
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Flyway-migrasjoner for PostgreSQL: navnekonvensjoner (V{n}__desc.sql), skjema for krav/feilmelding/filvalideringsfeil, DBListener-testing med TestContainers
Post-send livssyklus: StatusService poller /mottaksstatus; StoppKravService; RapportService + AvstemmingRouting-frontend for manuell reskontroføring
HOCON-basert konfigurasjon med PropertiesConfig singleton for Ktor batch-tjenester på NAIS (FSS)
Endring av eksisterende krav (endre rente og endre hovedstol): EndreKravService, request-DTOer, status-konformering og SKE API PUT-endepunkter
Kotest BehaviorSpec/MockK-mønstre for sokos-ske-krav: scenariostruktur, DBListener/SftpListener, MockHttpClient, circuit-breaker-reset og matchers
Idiomatic Kotlin: null safety, immutability, sealed types, structured concurrency, extension functions, DSL builders, Gradle Kotlin DSL
| name | slack-alerting |
| description | SlackService feilakkumulering og Tags-basert varsling for prosesseringsfeil i SKE-batch |
SlackService accumulates errors for a file/batch, then flushes them in a single call. Never call SlackClient.sendMessage() directly — accumulate first, send once.
slackService.addError(fileName, "Feil i validering av fil", errorMessages)
// ... more processing, more addError() calls ...
slackService.sendErrors() // flush once at the end, safe even if no errors accumulated
This prevents Slack rate-limiting and groups all errors for a file into one message.
class SlackService(private val slackClient: SlackClient = SlackClient()) {
fun addError(fileName: String, header: String, messages: Map<String, List<String>>)
fun addError(fileName: String, header: String, messages: Pair<String, String>)
fun addError(fileName: String, header: String, messages: List<Pair<String, String>>)
suspend fun sendErrors()
}
Internal state: MutableList<FileErrors>. sendErrors() iterates file errors, calls SlackClient.sendMessage() per header group, then clears the buffer.
The Tags enum maps specific SKE error types to on-call Slack user IDs and (optionally) a routine link:
private enum class Tags(
val personer: List<String>,
val rutineLink: String? = null,
val errorKey: String? = null,
) {
PERSON_EKSISTERER_IKKE(listOf(NAME_A, NAME_B)),
ORGANISASJON_ER_OPPHOERT(listOf(NAME_C, NAME_D), "https://confluence.adeo.no/…"),
FANT_IKKE_GYLDIG_KRAVIDENTIFIKATOR(listOf(NAME_E), errorKey = FeilResponse.CustomTitles.FANT_IKKE_GYLDIG_KRAVIDENTIFIKATOR),
// ...
;
companion object { val lookupMap: Map<String, Tags> = entries.associateBy { it.errorKey ?: it.name } }
}
The error key in the messages map passed to addError must match either it.errorKey (if set) or it.name exactly. SlackService.sendErrors() resolves it through lookupMap before calling SlackClient.sendMessage(...), so the right people are tagged.
valideringsFeil.error which comes directly from SKE in SCREAMING_SNAKE_CASE — use a matching enum name.FeilResponse.CustomTitles.FANT_IKKE_GYLDIG_KRAVIDENTIFIKATOR set as feilResponse.title): set errorKey to the shared constant and use that same value as the map key in messages.Adding a new tag:
Tags with personer (and optional rutineLink)name, no errorKey needederrorKey to itlookupMap and sendMessage() pick it upclass SlackClient(
private val slackEndpoint: String = PropertiesConfig.slackConfig.url,
private val client: HttpClient = slackHttpClient, // proxy-aware, needed on NAIS FSS
) {
suspend fun sendMessage(
header: String,
fileName: String,
messages: Map<String, List<String>>,
taggedPeople: List<String> = emptyList(),
rutineLink: String? = null,
)
}
Webhook URL comes from slack.url HOCON (env SOKOS_SKE_KRAV_SLACK_WEBHOOK_URL).
slack { url = ${SOKOS_SKE_KRAV_SLACK_WEBHOOK_URL} }
// Option 1: real SlackService with a no-op HTTP client
val slackService = SlackService(SlackClient(slackEndpoint = "", client = MockHttpClient.slackClient))
// Option 2: mock SlackService entirely
val slackServiceMock = mockk<SlackService> {
justRun { addError(any(), any(), any<List<Pair<String, String>>>()) }
coJustRun { sendErrors() }
}
MockHttpClient.slackClient is a pre-built HttpClient(MockEngine) that returns 200 OK to any request.
addError(...) + sendErrors() — never SlackClient.sendMessage() directly from service codesendErrors() exactly once at the end of each processing pass (e.g. per scheduler tick)Tags.name identical to the SKE error type stringerrorKey to the same shared constant used by feilResponse.titleTags entries (on-call people depend on them)Tags / config