Guest User

Untitled

a guest
Jul 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ## patch for retrying post and throwing an error upon failure in Facebooker::Service::CurlService::post_form
  2. def post_form(url,params,multipart=false)
  3. tries = 2
  4. begin
  5. curl = Curl::Easy.new(url.to_s) do |c|
  6. c.multipart_form_post = multipart
  7. c.timeout = 2 #second.. Facebooker.timeout
  8. end
  9. curl.http_post(*to_curb_params(params))
  10. curl.body_str
  11. rescue Curl::Err::TimeoutError => e
  12. tries -= 1
  13. sleep 0.1
  14. if tries > 0
  15. retry
  16. else
  17. raise Errno::ECONNRESET
  18. end
  19. rescue Curl::Err::GotNothingError => e
  20. tries -= 1
  21. sleep 0.1
  22. if tries > 0
  23. retry
  24. else
  25. raise Errno::ECONNRESET
  26. end
  27. end
  28. end
  29.  
  30. ## or you can remove the retry logic from post_form since Facebooker::Service::post has retry logic
  31. def post_form(url,params,multipart=false)
  32. begin
  33. curl = Curl::Easy.new(url.to_s) do |c|
  34. c.multipart_form_post = multipart
  35. c.timeout = 2 #second.. Facebooker.timeout
  36. end
  37. curl.http_post(*to_curb_params(params))
  38. curl.body_str
  39. rescue Curl::Err::TimeoutError => e
  40. raise Errno::ECONNRESET
  41. rescue Curl::Err::GotNothingError => e
  42. raise Errno::ECONNRESET
  43. end
  44. end
Add Comment
Please, Sign In to add comment