Skip to content

Commit b197a9a

Browse files
committed
Corrects a minor bug in ScheduledExecution
ScheduledExecution#dispatch_next_batch was returning either an empty array or an integer count of the number of rows processed by the method. The client of this method is Worker and Dispatcher #poll, and poll requires the count of the number of rows processed. This commit changes the returned empty array to an integer value of 0 for consistency’s sake. It also includes small updates to the tests for these methods.
1 parent e470071 commit b197a9a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

app/models/solid_queue/scheduled_execution.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class << self
1414
def dispatch_next_batch(batch_size)
1515
transaction do
1616
job_ids = next_batch(batch_size).non_blocking_lock.pluck(:job_id)
17-
if job_ids.empty? then []
17+
if job_ids.empty?
18+
0
1819
else
1920
SolidQueue.instrument(:dispatch_scheduled, batch_size: batch_size) do |payload|
2021
payload[:size] = dispatch_jobs(job_ids)

test/unit/dispatcher_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DispatcherTest < ActiveSupport::TestCase
9696
dispatcher = SolidQueue::Dispatcher.new(polling_interval: 10, batch_size: 1)
9797
dispatcher.expects(:interruptible_sleep).with(0.seconds).at_least(3)
9898
dispatcher.expects(:interruptible_sleep).with(dispatcher.polling_interval).at_least_once
99+
dispatcher.expects(:handle_thread_error).never
99100

100101
3.times { AddToBufferJob.set(wait: 0.1).perform_later("I'm scheduled") }
101102
assert_equal 3, SolidQueue::ScheduledExecution.count
@@ -112,8 +113,10 @@ class DispatcherTest < ActiveSupport::TestCase
112113
dispatcher = SolidQueue::Dispatcher.new(polling_interval: 10, batch_size: 1)
113114
dispatcher.expects(:interruptible_sleep).with(0.seconds).never
114115
dispatcher.expects(:interruptible_sleep).with(dispatcher.polling_interval).at_least_once
116+
dispatcher.expects(:handle_thread_error).never
117+
115118
dispatcher.start
116-
sleep 0.1
119+
wait_while_with_timeout(1.second) { !SolidQueue::ScheduledExecution.exists? }
117120
end
118121

119122
private

test/unit/worker_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class WorkerTest < ActiveSupport::TestCase
176176

177177
@worker.expects(:interruptible_sleep).with(10.minutes).at_least_once
178178
@worker.expects(:interruptible_sleep).with(@worker.polling_interval).never
179+
@worker.expects(:handle_thread_error).never
179180

180181
@worker.start
181182
sleep 1.second
@@ -186,6 +187,7 @@ class WorkerTest < ActiveSupport::TestCase
186187

187188
@worker.expects(:interruptible_sleep).with(@worker.polling_interval).at_least_once
188189
@worker.expects(:interruptible_sleep).with(10.minutes).never
190+
@worker.expects(:handle_thread_error).never
189191

190192
@worker.start
191193
sleep 1.second

0 commit comments

Comments
 (0)