HH-564: harden durable realtime publish boundaries (#139)

* fix(HH-564): harden durable realtime enqueue

* fix(HH-564): wire production SSE stream

---------

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-23 23:38:00 +08:00
committed by GitHub
co-authored by rogee
parent cb0b554e94
commit f36606a4f2
14 changed files with 423 additions and 12 deletions
+13 -7
View File
@@ -317,14 +317,20 @@ func (wp *WorkerPool) persistJob(ctx context.Context, db *gorm.DB, jobType strin
}
}
if err := db.WithContext(ctx).Create(job).Error; err != nil {
if job.IdempotencyKey != "" {
var existing model.BackgroundJob
if findErr := db.WithContext(ctx).Where("idempotency_key = ?", job.IdempotencyKey).First(&existing).Error; findErr == nil {
return &existing, false, nil
}
query := db.WithContext(ctx)
if job.IdempotencyKey != "" {
query = query.Clauses(clause.OnConflict{DoNothing: true})
}
result := query.Create(job)
if result.Error != nil {
return nil, false, result.Error
}
if job.IdempotencyKey != "" && result.RowsAffected == 0 {
var existing model.BackgroundJob
if err := db.WithContext(ctx).Where("idempotency_key = ?", job.IdempotencyKey).First(&existing).Error; err != nil {
return nil, false, err
}
return nil, false, err
return &existing, false, nil
}
return job, true, nil
}