-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2be46e
commit 71c0686
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
backend/src/main/kotlin/app/ehrenamtskarte/backend/common/webservice/HealthHandler.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,29 @@ | ||
package app.ehrenamtskarte.backend.application.webservice | ||
|
||
import app.ehrenamtskarte.backend.config.BackendConfiguration | ||
import app.ehrenamtskarte.backend.projects.database.ProjectEntity | ||
import app.ehrenamtskarte.backend.projects.database.Projects | ||
import io.javalin.http.Context | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import org.jetbrains.exposed.exceptions.ExposedSQLException | ||
import org.postgresql.util.PSQLException | ||
import java.lang.System | ||
import java.net.ConnectException | ||
|
||
class HealthHandler(private val config: BackendConfiguration) { | ||
fun handle(ctx: Context) { | ||
try { | ||
transaction { | ||
val projectIds = config.projects.map { it.id } | ||
val projects = ProjectEntity.find { Projects.project inList projectIds } | ||
if (projects.empty()) { | ||
ctx.status(502) | ||
return | ||
} | ||
} | ||
ctx.status(200) | ||
} catch (exception: ExposedSQLException) { | ||
ctx.status(502) | ||
} | ||
} | ||
} |
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