타임아웃 조건 완화 등

This commit is contained in:
Lectom C Han
2025-12-09 15:49:15 +09:00
parent 2d3345bb6d
commit c4bb3525d3
2 changed files with 19 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ import (
const (
defaultMMDBPath = "/data/GeoLite2-City.mmdb"
defaultSchema = "geoip"
defaultLoaderTimeout = 5 * time.Minute
defaultLoaderTimeout = 30 * time.Minute
)
type cityRecord struct {
@@ -57,18 +57,19 @@ type cityRow struct {
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), defaultLoaderTimeout)
defer cancel()
dbURL := os.Getenv("DATABASE_URL")
if dbURL == "" {
log.Fatal("DATABASE_URL is required")
}
mmdbPath := env("GEOIP_DB_PATH", defaultMMDBPath)
timeout := envDuration("GEOIP_LOADER_TIMEOUT", defaultLoaderTimeout)
skipIfSame := envBool("GEOIP_LOADER_SKIP_IF_SAME_HASH", true)
force := envBool("GEOIP_LOADER_FORCE", false)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
log.Printf("starting mmdb load from %s", mmdbPath)
hash, err := fileSHA256(mmdbPath)
@@ -131,6 +132,18 @@ func envBool(key string, fallback bool) bool {
return parsed
}
func envDuration(key string, fallback time.Duration) time.Duration {
val := os.Getenv(key)
if val == "" {
return fallback
}
d, err := time.ParseDuration(val)
if err != nil {
return fallback
}
return d
}
func fileSHA256(path string) (string, error) {
f, err := os.Open(path)
if err != nil {

View File

@@ -12,9 +12,11 @@ services:
- PORT=${PORT:-8080}
- GEOIP_DB_PATH=${GEOIP_DB_PATH:-/data/GeoLite2-City.mmdb}
- GEOIP_BACKEND=${GEOIP_BACKEND:-mmdb}
- GEOIP_LOADER_TIMEOUT=${GEOIP_LOADER_TIMEOUT:-30m}
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}/${POSTGRES_DB}?sslmode=disable
command: >
sh -c '
set -e;
if [ "${GEOIP_BACKEND}" = "postgres" ]; then
echo "[api] running geoip-loader before api start";
geoip-loader;