docker-healthchecks/maintenance.nu

64 lines
1.6 KiB
Text
Raw Normal View History

2024-09-07 12:11:45 -05:00
def healthcheck_start [
url: record
] {
if not ($env | get -i HEALTHCHECK_URL | is-empty ) {
http get --full --max-time 10 ($url | update path $"($in.path)/start" | url join) | ignore
}
}
def healthcheck_log [
url: record
log: string
] {
if not ($url | is-empty ) {
http post --max-time 10 ($url | update path $"($in.path)/log" | url join) $log | ignore
}
}
def healthcheck_fail [
url: record
log: string
] {
if not ($url | is-empty ) {
http post --full --max-time 10 ($url | update path $"($in.path)/fail" | url join) $log | ignore
}
}
def healthcheck_stop [
url: record
] {
if not ($url | is-empty ) {
http get --full --max-time 10 ($url | url join) | ignore
}
}
def main [] {
let rid = (random uuid)
let healthcheck_url = if not ($env | get -i HEALTHCHECK_URL | is-empty) {
$env.HEALTHCHECK_URL | url parse | update params ($in | get params | insert rid $rid)
} else {
{}
}
healthcheck_start $healthcheck_url
let result = (do {manage prunenotifications} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage pruneusers} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage prunetokenbucket} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
let result = (do {manage pruneflips} | complete)
print ($result.stdout | str trim --right)
healthcheck_log $healthcheck_url $result.stdout
healthcheck_stop $healthcheck_url
}