fix: recover transient stock history failures within bounded deadlines

This commit is contained in:
2026-10-09 23:20:23 +08:00
parent c8c61d29bf
commit 2acfc64d58
6 changed files with 85 additions and 6 deletions
+8 -1
View File
@@ -19,7 +19,7 @@ func NewRouter(health *service.HealthService, logger *zap.Logger, identity Ident
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.Use(func(c *gin.Context) {
ctx, cancel := context.WithTimeout(c.Request.Context(), 5*time.Second)
ctx, cancel := context.WithTimeout(c.Request.Context(), requestTimeout(c.Request))
defer cancel()
if identity.PublicOrigin != "" {
ctx = context.WithValue(ctx, publicOriginContextKey{}, identity.PublicOrigin)
@@ -87,3 +87,10 @@ func NewRouter(health *service.HealthService, logger *zap.Logger, identity Ident
})
return r
}
func requestTimeout(r *http.Request) time.Duration {
if r.Method == http.MethodGet && (r.URL.Path == "/api/admin/v1/market/history" || r.URL.Path == "/api/v1/market/history") || r.Method == http.MethodPost && r.URL.Path == "/api/admin/v1/backtests/from-market" {
return 35 * time.Second
}
return 5 * time.Second
}