reduce error footprint

This commit is contained in:
Roy Han 2024-07-15 10:57:01 -07:00
parent 1f73889f34
commit 907b038ff0

View File

@ -305,8 +305,9 @@ func (s *Server) EmbedHandler(c *gin.Context) {
} }
reqEmbedArray := make([]string, len(reqEmbed)) reqEmbedArray := make([]string, len(reqEmbed))
errCh := make(chan error, len(reqEmbed)) errCh := make(chan error, 1)
sem := make(chan struct{}, 5) successCh := make(chan bool, 1)
sem := make(chan struct{}, 2)
var wg sync.WaitGroup var wg sync.WaitGroup
var mu sync.Mutex var mu sync.Mutex
for i, s := range reqEmbed { for i, s := range reqEmbed {
@ -342,11 +343,17 @@ func (s *Server) EmbedHandler(c *gin.Context) {
} }
go func() { go func() {
wg.Wait() wg.Wait()
successCh <- true
close(errCh) close(errCh)
}() }()
for err := range errCh {
if err != nil { select {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) case err := <-errCh:
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
case success := <-successCh:
if !success {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to process all embeddings"})
return return
} }
} }