mirror of
https://github.com/rishikanthc/Scriberr.git
synced 2026-06-28 06:46:25 +00:00
fix: quiet empty transcription queue polls
This commit is contained in:
@@ -191,14 +191,19 @@ func (r *jobRepository) ClaimNextTranscription(ctx context.Context, workerID str
|
||||
var claimed models.TranscriptionJob
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var candidate models.TranscriptionJob
|
||||
if err := tx.
|
||||
result := tx.
|
||||
Where("status = ?", models.StatusPending).
|
||||
Order("queued_at ASC, created_at ASC, id ASC").
|
||||
First(&candidate).Error; err != nil {
|
||||
return err
|
||||
Limit(1).
|
||||
Find(&candidate)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
now := time.Now()
|
||||
result := tx.Model(&models.TranscriptionJob{}).
|
||||
result = tx.Model(&models.TranscriptionJob{}).
|
||||
Where("id = ? AND status = ?", candidate.ID, models.StatusPending).
|
||||
Updates(map[string]any{
|
||||
"status": models.StatusProcessing,
|
||||
|
||||
@@ -106,6 +106,16 @@ func TestJobRepositoryEnqueueAndClaimFIFO(t *testing.T) {
|
||||
assert.Equal(t, newer.ID, claimed.ID)
|
||||
}
|
||||
|
||||
func TestJobRepositoryClaimNextReturnsNotFoundWhenQueueEmpty(t *testing.T) {
|
||||
db := openJobQueueTestDB(t)
|
||||
repo := NewJobRepository(db)
|
||||
|
||||
claimed, err := repo.ClaimNextTranscription(context.Background(), "worker-a", time.Now().Add(time.Minute))
|
||||
|
||||
require.ErrorIs(t, err, gorm.ErrRecordNotFound)
|
||||
require.Nil(t, claimed)
|
||||
}
|
||||
|
||||
func TestJobRepositoryConcurrentClaimsDoNotDuplicateJobs(t *testing.T) {
|
||||
db := openJobQueueTestDB(t)
|
||||
user := createQueueTestUser(t, db)
|
||||
|
||||
Reference in New Issue
Block a user