Skip to content

Commit

Permalink
Change delayed_jobs_reserve index
Browse files Browse the repository at this point in the history
Add WHERE condition. Jobs that failed are only kept for debugging
purposes, they are not taken into account when reserving a job. The
corresponding SELECT statement [1] includes 'WHERE failed_at IS NULL',
so the corresponding index can omit failed jobs.

Partial indexes are not supported for MySQL, thus this change is only
for PostgreSQL.

[1] https://github.com/TalentBox/delayed_job_sequel/
      blob/938ff68e98b44bbc391805c672a74c5ee3aef08b/
      lib/delayed/backend/sequel.rb#L26
  • Loading branch information
philippthun committed Feb 22, 2024
1 parent b9f2933 commit 1077bae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions db/migrations/20240222131500_change_delayed_jobs_reserve_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Sequel.migration do
up do
if database_type == :postgres
drop_index :delayed_jobs, nil, name: :delayed_jobs_reserve, options: %i[if_exists concurrently]
add_index :delayed_jobs, %i[queue locked_at locked_by failed_at run_at priority],
where: { failed_at: nil }, name: :delayed_jobs_reserve, options: %i[if_not_exists concurrently]
end
end

down do
if database_type == :postgres
drop_index :delayed_jobs, nil, name: :delayed_jobs_reserve, options: %i[if_exists concurrently]
add_index :delayed_jobs, %i[queue locked_at locked_by failed_at run_at priority],
name: :delayed_jobs_reserve, options: %i[if_not_exists concurrently]
end
end
end

0 comments on commit 1077bae

Please sign in to comment.