Skip to content

Commit

Permalink
fix: playbook run duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 20, 2024
1 parent 0ce6490 commit 34b8102
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion playbook/run_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,13 @@ func RunConsumer(ctx context.Context) (int, error) {
FROM playbook_runs
INNER JOIN playbooks ON playbooks.id = playbook_runs.playbook_id
WHERE status IN (?, ?) AND scheduled_time <= NOW()
AND agent_id = ?
ORDER BY scheduled_time
FOR UPDATE SKIP LOCKED
LIMIT 1
`
var run models.PlaybookRun
if err := tx.Raw(query, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusSleeping).First(&run).Error; err != nil {
if err := tx.Raw(query, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusSleeping, uuid.Nil).First(&run).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
Expand Down

0 comments on commit 34b8102

Please sign in to comment.