Skip to content

Commit 808d9fb

Browse files
committed
Reorder scheduled execution code a bit
1 parent a7f126f commit 808d9fb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

app/models/solid_queue/scheduled_execution.rb

+17-9
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ def prepare_next_batch(batch_size)
1515

1616
private
1717
def prepare_batch(batch)
18-
prepared_at = Time.current
18+
if batch.empty? then []
19+
else
20+
promote_batch_to_ready(batch)
21+
end
22+
end
1923

20-
rows = batch.map do |scheduled_execution|
21-
scheduled_execution.ready_attributes.merge(created_at: prepared_at)
24+
def promote_batch_to_ready(batch)
25+
rows = ready_rows_from_batch(batch)
26+
27+
SolidQueue::ReadyExecution.insert_all(rows)
28+
SolidQueue::ReadyExecution.where(job_id: batch.map(&:job_id)).pluck(:job_id).tap do |enqueued_job_ids|
29+
where(job_id: enqueued_job_ids).delete_all
2230
end
31+
end
2332

24-
if rows.empty? then []
25-
else
26-
SolidQueue::ReadyExecution.insert_all(rows)
27-
SolidQueue::ReadyExecution.where(job_id: batch.map(&:job_id)).pluck(:job_id).tap do |enqueued_job_ids|
28-
where(job_id: enqueued_job_ids).delete_all
29-
end
33+
def ready_rows_from_batch(batch)
34+
prepared_at = Time.current
35+
36+
batch.map do |scheduled_execution|
37+
scheduled_execution.ready_attributes.merge(created_at: prepared_at)
3038
end
3139
end
3240
end

0 commit comments

Comments
 (0)