fixed glm panic

This commit is contained in:
Mazyar
2025-12-28 15:58:33 +03:30
parent f6bdcc6d7c
commit a95944d4c6
3 changed files with 35 additions and 13 deletions
+2 -1
View File
@@ -223,7 +223,8 @@ func InitGLMService(conf GLMConfig, log logger.Logger) *glm.SDK {
log.Error("Failed to initialize GLM SDK", map[string]interface{}{ log.Error("Failed to initialize GLM SDK", map[string]interface{}{
"error": err.Error(), "error": err.Error(),
}) })
panic(fmt.Sprintf("Failed to initialize GLM SDK: %v", err)) log.Warn("GLM service will be disabled, translation features will not be available", map[string]interface{}{})
return nil
} }
log.Info("GLM SDK initialized successfully", map[string]interface{}{ log.Info("GLM SDK initialized successfully", map[string]interface{}{
+5
View File
@@ -39,6 +39,11 @@ func main() {
// Initialize GLM service // Initialize GLM service
glmService := bootstrap.InitGLMService(config.GLM, appLogger) glmService := bootstrap.InitGLMService(config.GLM, appLogger)
if glmService != nil {
appLogger.Info("GLM service initialized successfully", map[string]interface{}{})
} else {
appLogger.Warn("GLM service not available, translation features will be disabled", map[string]interface{}{})
}
// Initialize scraper service // Initialize scraper service
scraperService := bootstrap.InitScraperService(*config, appLogger) scraperService := bootstrap.InitScraperService(*config, appLogger)
+28 -12
View File
@@ -392,28 +392,44 @@ func (w *NoticeWorker) ToTender(n *notice.Notice) (*tender.Tender, error) {
} }
} }
title, err := w.GLM.Translate(context.Background(), n.Title, n.NoticeLanguageCode, "en") var title string
if err != nil { if w.GLM != nil {
w.Logger.Error("Failed to translate title", map[string]interface{}{ title, err = w.GLM.Translate(context.Background(), n.Title, n.NoticeLanguageCode, "en")
if err != nil {
w.Logger.Error("Failed to translate title", map[string]interface{}{
"notice_publication_id": n.NoticePublicationID,
"country_code": n.CountryCode,
"content": n.Title,
"error": err.Error(),
})
title = n.Title
}
} else {
w.Logger.Warn("GLM service not available, using original title", map[string]interface{}{
"notice_publication_id": n.NoticePublicationID, "notice_publication_id": n.NoticePublicationID,
"country_code": n.CountryCode, "country_code": n.CountryCode,
"content": n.Title,
"error": err.Error(),
}) })
title = n.Title title = n.Title
// return err
} }
description, err := w.GLM.Translate(context.Background(), n.Description, n.NoticeLanguageCode, "en") var description string
if err != nil { if w.GLM != nil {
w.Logger.Error("Failed to translate description", map[string]interface{}{ description, err = w.GLM.Translate(context.Background(), n.Description, n.NoticeLanguageCode, "en")
if err != nil {
w.Logger.Error("Failed to translate description", map[string]interface{}{
"notice_publication_id": n.NoticePublicationID,
"country_code": n.CountryCode,
"content": n.Description,
"error": err.Error(),
})
description = n.Description
}
} else {
w.Logger.Warn("GLM service not available, using original description", map[string]interface{}{
"notice_publication_id": n.NoticePublicationID, "notice_publication_id": n.NoticePublicationID,
"country_code": n.CountryCode, "country_code": n.CountryCode,
"content": n.Description,
"error": err.Error(),
}) })
description = n.Description description = n.Description
// return err
} }
t.Title = title t.Title = title
t.Description = description t.Description = description