Skip to content

Commit

Permalink
Fix index on blocked_executions for releasing and add index on sema…
Browse files Browse the repository at this point in the history
…phores

Also, include `job_id` in the ORDER when releasing blocked executions.

Thanks to @djmb for the suggestions.
  • Loading branch information
rosa committed Nov 22, 2023
1 parent 7c3007a commit ed30280
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion app/models/solid_queue/blocked_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class BlockedExecution < SolidQueue::Execution
has_one :semaphore, foreign_key: :key, primary_key: :concurrency_key

scope :releasable, -> { left_outer_joins(:semaphore).merge(Semaphore.available.or(Semaphore.where(id: nil))) }
scope :ordered, -> { order(priority: :asc) }

class << self
def unblock(count)
Expand Down
2 changes: 2 additions & 0 deletions app/models/solid_queue/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Execution < SolidQueue::Record

self.abstract_class = true

scope :ordered, -> { order(priority: :asc, job_id: :asc) }

belongs_to :job

alias_method :discard, :destroy
Expand Down
1 change: 0 additions & 1 deletion app/models/solid_queue/ready_execution.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module SolidQueue
class ReadyExecution < Execution
scope :queued_as, ->(queue_name) { where(queue_name: queue_name) }
scope :ordered, -> { order(priority: :asc, job_id: :asc) }

assume_attributes_from_job

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def change

t.datetime :created_at, null: false

t.index [ :priority, :concurrency_key, :queue_name, :job_id ], name: "index_solid_queue_blocked_executions_for_release"
t.index [ :priority, :concurrency_key, :job_id ], name: "index_solid_queue_blocked_executions_for_release"
end

create_table :solid_queue_semaphores do |t|
Expand All @@ -22,6 +22,8 @@ def change
t.datetime :expires_at, null: false, index: true

t.timestamps

t.index [ :key, :value ]
end
end
end
3 changes: 2 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
t.string "concurrency_key", null: false
t.datetime "created_at", null: false
t.index ["job_id"], name: "index_solid_queue_blocked_executions_on_job_id", unique: true
t.index ["priority", "concurrency_key", "queue_name", "job_id"], name: "index_solid_queue_blocked_executions_for_release"
t.index ["priority", "concurrency_key", "job_id"], name: "index_solid_queue_blocked_executions_for_release"
end

create_table "solid_queue_claimed_executions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
Expand Down Expand Up @@ -102,6 +102,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["expires_at"], name: "index_solid_queue_semaphores_on_expires_at"
t.index ["key", "value"], name: "index_solid_queue_semaphores_on_key_and_value"
t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true
end

Expand Down

0 comments on commit ed30280

Please sign in to comment.