Skip to content

Commit

Permalink
Add redo command
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexParamonov committed Nov 9, 2014
1 parent 255d87d commit 0b0b5c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/processor/process_runner/threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def call(processor)
begin
thread_data_processor.process(thread_record)
rescue StandardError => exception
thread_data_processor.record_error thread_record, exception
command = catch(:command) do
thread_data_processor.record_error thread_record, exception
end

# NOTE: redo can not be moved into a method or block
# to break from records loop, use Exception
redo if command == :redo
end
end

Expand Down
15 changes: 13 additions & 2 deletions spec/processor/process_runner/specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
end

describe "exception handling" do
describe "processing a record raised StandardError" do
let(:records) { 1..3 }
let(:records) { 1..3 }

describe "processing a record raised StandardError" do
it "should continue processing" do
processor.should_receive(:process).exactly(3).times.and_raise(StandardError)
expect { process_runner.call processor }.to_not raise_error
Expand All @@ -35,5 +35,16 @@
expect { process_runner.call processor }.to raise_error(Exception)
end
end

describe "processing a record have requested a command run" do
it "should run redo command" do
processor.should_receive(:process).with(1).once.and_raise(StandardError)
processor.should_receive(:process).with(1).once
processor.should_receive(:process).exactly(2).times

processor.should_receive(:record_error).once.and_throw(:command, :redo)
process_runner.call processor
end
end
end
end

0 comments on commit 0b0b5c3

Please sign in to comment.