Skip to content

Commit

Permalink
Restore outer attempt condition when fetching jobs
Browse files Browse the repository at this point in the history
In some situations a condition to ensure the attempts don't exceed max
attempts is still necessary. By checking the attempts outside the CTE we
maintain optimal query performance for the large scan that finds jobs,
and only apply the check in the small _outer_ query.
  • Loading branch information
sorentwo committed May 11, 2023
1 parent 41156ab commit 8eb5437
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/oban/engines/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ defmodule Oban.Engines.Basic do
|> with_cte("subset", as: ^subset_query)
|> join(:inner, [j], x in fragment(~s("subset")), on: true)
|> where([j, x], j.id == x.id)
|> where([j, _], j.attempt < j.max_attempts)
|> select([j, _], j)

updates = [
Expand Down

0 comments on commit 8eb5437

Please sign in to comment.