Created
December 21, 2012 09:02
-
-
Save anonymous/4351607 to your computer and use it in GitHub Desktop.
the function ingoing_inspection_nsw is long running. This is being called from the view and the pdf being returned as application/pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retryable(options = {}) | |
opts = { :tries => 1, :on => Exception }.merge(options) | |
retry_exception, retries = opts[:on], opts[:tries] | |
begin | |
return yield | |
rescue retry_exception | |
if (retries -= 1) > 0 | |
sleep 2 | |
retry | |
else | |
raise | |
end | |
end | |
end | |
def create_report | |
if @inspection.type == 'RoutineInspection' | |
puts "---CR> CREATING ROUTINE INSPECTION REPORT" | |
pdf = routine_inspection_generic | |
else | |
puts "---CR> CREATING INGOING INSPECTION REPORT" | |
thread = Thread.new do | |
pdf = ingoing_inspection_nsw | |
end | |
retryable(:tries => 10, :on => ActionView::Template::Error) do | |
thread.join | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment