Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Forked from anonymous/gist:4351607
Last active December 10, 2015 00:29
Show Gist options
  • Save tagrudev/4351631 to your computer and use it in GitHub Desktop.
Save tagrudev/4351631 to your computer and use it in GitHub Desktop.
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.join
end
pdf
end
@karlmikko
Copy link

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 => Timeout::Error) do
          thread.join
      end
end
pdf

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment