fix article generation task status logging
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
||||
sharedcache "github.com/geo-platform/tenant-api/internal/shared/cache"
|
||||
@@ -31,6 +32,7 @@ type TemplateService struct {
|
||||
cfg generationRuntimeConfig
|
||||
configProvider runtimeConfigProvider
|
||||
cache sharedcache.Cache
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
type generationJob struct {
|
||||
@@ -80,6 +82,11 @@ func (s *TemplateService) WithConfigProvider(provider runtimeConfigProvider) *Te
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TemplateService) WithLogger(logger *zap.Logger) *TemplateService {
|
||||
s.logger = logger
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *TemplateService) runtimeConfig() generationRuntimeConfig {
|
||||
if s != nil && s.configProvider != nil {
|
||||
if cfg := s.configProvider.Current(); cfg != nil {
|
||||
@@ -584,14 +591,28 @@ func (s *TemplateService) failGeneration(ctx context.Context, job generationJob,
|
||||
articleRepo := repository.NewArticleRepository(s.pool)
|
||||
quotaRepo := repository.NewQuotaRepository(s.pool)
|
||||
|
||||
_ = auditRepo.UpdateGenerationTaskStatus(cleanupCtx, repository.GenerationTaskStatusInput{
|
||||
if err := auditRepo.UpdateGenerationTaskStatus(cleanupCtx, repository.GenerationTaskStatusInput{
|
||||
ID: job.TaskID,
|
||||
TenantID: job.TenantID,
|
||||
Status: "failed",
|
||||
ErrorMessage: &errMsg,
|
||||
CompletedAt: &now,
|
||||
})
|
||||
_ = articleRepo.UpdateArticleGenerateStatus(cleanupCtx, job.ArticleID, job.TenantID, "failed")
|
||||
}); err != nil && s.logger != nil {
|
||||
s.logger.Warn("template generation task failed status update failed",
|
||||
zap.Error(err),
|
||||
zap.Int64("task_id", job.TaskID),
|
||||
zap.Int64("article_id", job.ArticleID),
|
||||
zap.String("stage", stage),
|
||||
)
|
||||
}
|
||||
if err := articleRepo.UpdateArticleGenerateStatus(cleanupCtx, job.ArticleID, job.TenantID, "failed"); err != nil && s.logger != nil {
|
||||
s.logger.Warn("template generation article failed status update failed",
|
||||
zap.Error(err),
|
||||
zap.Int64("task_id", job.TaskID),
|
||||
zap.Int64("article_id", job.ArticleID),
|
||||
zap.String("stage", stage),
|
||||
)
|
||||
}
|
||||
|
||||
balance, balanceErr := quotaRepo.GetCurrentBalance(cleanupCtx, job.TenantID, "article_generation")
|
||||
if balanceErr == nil {
|
||||
|
||||
Reference in New Issue
Block a user