Files
fn_registry/functions/infra/health_check_http.md
T
egutierrez 90693fb32f feat: funciones infra — Docker, deploy, build y health check
Funciones impuras para gestión de contenedores: docker_build_image,
docker_compose_up/down, docker_volume_create/list/remove,
generate_dockerfile, write_dockerfile, go_build_binary, health_check_http,
deploy_app y stop_app. Todas con tests unitarios donde aplica.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 14:24:12 +02:00

37 lines
1.3 KiB
Markdown

---
name: health_check_http
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func HealthCheckHTTP(url string, timeoutSecs, intervalMs int) error"
description: "Hace polling HTTP GET a un endpoint hasta recibir status 200 o hasta agotar el timeout. Útil para esperar que un servicio levante antes de continuar un pipeline."
tags: [http, health, check, polling, wait, infra]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [fmt, net/http, time]
tested: true
tests: ["retorna nil cuando el servidor responde 200", "retorna error si el timeout se agota", "respeta el intervalo entre intentos"]
test_file_path: "functions/infra/health_check_http_test.go"
file_path: "functions/infra/health_check_http.go"
---
## Ejemplo
```go
// Esperar hasta 60s a que Metabase levante, polling cada 2s
err := HealthCheckHTTP("http://localhost:3000/api/health", 60, 2000)
if err != nil {
log.Fatal("Servicio no disponible:", err)
}
fmt.Println("Servicio listo")
```
## Notas
Usa solo net/http de la stdlib, sin dependencias externas. El cliente HTTP tiene timeout de intervalMs + 500ms para no bloquear el loop. Retorna el ultimo error si el timeout expira. No sigue redirects especiales — cualquier respuesta 200 OK es exito.