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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user