Skip to content

Commit

Permalink
Improve a bit some execution methods (DRY and order)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosa committed Nov 20, 2023
1 parent 8a67173 commit 85f54a2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/solid_queue/blocked_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def acquire_concurrency_lock
end

def promote_to_ready
ReadyExecution.create!(job_id: job_id, queue_name: queue_name, priority: priority)
ReadyExecution.create!(ready_attributes)
end
end
end
6 changes: 2 additions & 4 deletions app/models/solid_queue/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class Execution < SolidQueue::Record

alias_method :discard, :destroy

class << self
def queued_as(queues)
QueueParser.new(queues, self).scoped_relation
end
def ready_attributes
attributes.slice("job_id", "queue_name", "priority")
end
end
end
4 changes: 4 additions & 0 deletions app/models/solid_queue/ready_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def claim(queues, limit, process_id)
end
end

def queued_as(queues)
QueueParser.new(queues, self).scoped_relation
end

private
def select_candidates(queues, limit)
queued_as(queues).not_paused.ordered.limit(limit).lock("FOR UPDATE SKIP LOCKED").pluck(:job_id)
Expand Down
6 changes: 1 addition & 5 deletions app/models/solid_queue/scheduled_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def prepare_batch(batch)
prepared_at = Time.current

rows = batch.map do |scheduled_execution|
scheduled_execution.execution_ready_attributes.merge(created_at: prepared_at)
scheduled_execution.ready_attributes.merge(created_at: prepared_at)
end

if rows.any?
Expand All @@ -23,8 +23,4 @@ def prepare_batch(batch)
SolidQueue.logger.info("[SolidQueue] Prepared scheduled batch with #{rows.size} jobs at #{prepared_at}")
end
end

def execution_ready_attributes
attributes.slice("job_id", "queue_name", "priority")
end
end

0 comments on commit 85f54a2

Please sign in to comment.