Skip to content

Commit

Permalink
extracts worker.perform so call can be enhanced
Browse files Browse the repository at this point in the history
- defines execute_job as an API hook
  • Loading branch information
jejacks0n committed Sep 10, 2014
1 parent 0de364d commit 7714d19
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/sidekiq/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def process(work)

stats(worker, msg, queue) do
Sidekiq.server_middleware.invoke(worker, msg, queue) do
worker.perform(*cloned(msg['args']))
execute_job(worker, cloned(msg['args']))
end
end
rescue Sidekiq::Shutdown
Expand All @@ -71,6 +71,10 @@ def inspect
"<Processor##{object_id.to_s(16)}>"
end

def execute_job(worker, cloned_args)
worker.perform(*cloned_args)
end

private

def thread_identity
Expand Down
8 changes: 6 additions & 2 deletions lib/sidekiq/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def drain
while job = jobs.shift do
worker = new
worker.jid = job['jid']
worker.perform(*job['args'])
execute_job(worker, job['args'])
end
end

Expand All @@ -163,7 +163,11 @@ def perform_one
job = jobs.shift
worker = new
worker.jid = job['jid']
worker.perform(*job['args'])
execute_job(worker, job['args'])
end

def execute_job(worker, args)
worker.perform(*args)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/test_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def work(msg, queue='queue:default')
assert_equal 1, $invokes
end

it 'executes a worker as expected' do
worker = Minitest::Mock.new
worker.expect(:perform, nil, [1, 2, 3])
@processor.execute_job(worker, [1, 2, 3])
end

it 'passes exceptions to ExceptionHandler' do
actor = Minitest::Mock.new
actor.expect(:real_thread, nil, [nil, Thread])
Expand Down
6 changes: 6 additions & 0 deletions test/test_testing_fake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,11 @@ def perform
assert_equal 1, FirstWorker.count
assert_equal 1, SecondWorker.count
end

it 'can execute a job' do
worker = Minitest::Mock.new
worker.expect(:perform, nil, [1, 2, 3])
DirectWorker.execute_job(worker, [1, 2, 3])
end
end
end

0 comments on commit 7714d19

Please sign in to comment.