fix(tenant): resolve desktop retry article id via publish record/batch
Fall back to looking up article_id from publish_records or publish_batches
when the desktop task payload lacks article_id at the top level. Covers
payloads that only carry content_ref.{article_id,id}, publish_record_id,
or publish_batch_id, preventing spurious 40096 errors when retrying
older desktop tasks.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -264,9 +264,9 @@ func (s *PublishJobService) RetryByDesktopTask(
|
||||
}
|
||||
|
||||
payload := unmarshalJSONObject(task.Payload)
|
||||
articleID, ok := extractInt64FromMap(payload, "article_id")
|
||||
if !ok || articleID <= 0 {
|
||||
return nil, response.ErrBadRequest(40096, "desktop_task_article_missing", "desktop publish task is missing article_id")
|
||||
articleID, err := s.resolveRetryArticleID(ctx, client.TenantID, payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
title := strings.TrimSpace(stringPointerValue(extractStringPointer(payload, "title")))
|
||||
@@ -289,6 +289,61 @@ func (s *PublishJobService) RetryByDesktopTask(
|
||||
})
|
||||
}
|
||||
|
||||
func (s *PublishJobService) resolveRetryArticleID(ctx context.Context, tenantID int64, payload map[string]any) (int64, error) {
|
||||
if articleID, ok := resolveRetryArticleIDFromPayload(payload); ok {
|
||||
return articleID, nil
|
||||
}
|
||||
|
||||
if publishRecordID, ok := extractInt64FromMap(payload, "publish_record_id"); ok && publishRecordID > 0 {
|
||||
var articleID int64
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
SELECT article_id
|
||||
FROM publish_records
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
`, publishRecordID, tenantID).Scan(&articleID)
|
||||
if err == nil && articleID > 0 {
|
||||
return articleID, nil
|
||||
}
|
||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||
return 0, response.ErrInternal(50113, "desktop_publish_record_lookup_failed", "failed to lookup desktop publish record")
|
||||
}
|
||||
}
|
||||
|
||||
if publishBatchID, ok := extractInt64FromMap(payload, "publish_batch_id"); ok && publishBatchID > 0 {
|
||||
var articleID int64
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
SELECT article_id
|
||||
FROM publish_batches
|
||||
WHERE id = $1 AND tenant_id = $2
|
||||
`, publishBatchID, tenantID).Scan(&articleID)
|
||||
if err == nil && articleID > 0 {
|
||||
return articleID, nil
|
||||
}
|
||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||
return 0, response.ErrInternal(50114, "desktop_publish_batch_lookup_failed", "failed to lookup desktop publish batch")
|
||||
}
|
||||
}
|
||||
|
||||
return 0, response.ErrBadRequest(40096, "desktop_task_article_missing", "desktop publish task is missing article_id")
|
||||
}
|
||||
|
||||
func resolveRetryArticleIDFromPayload(payload map[string]any) (int64, bool) {
|
||||
if articleID, ok := extractInt64FromMap(payload, "article_id"); ok && articleID > 0 {
|
||||
return articleID, true
|
||||
}
|
||||
if len(payload) == 0 {
|
||||
return 0, false
|
||||
}
|
||||
nestedContentRef, ok := payload["content_ref"].(map[string]any)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
if articleID, ok := extractInt64FromMap(nestedContentRef, "article_id", "id"); ok && articleID > 0 {
|
||||
return articleID, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (s *PublishJobService) logWarn(message string, err error, fields ...zap.Field) {
|
||||
if s.logger == nil || err == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user