lib/star/file.rb in star-1.2.0 vs lib/star/file.rb in star-1.3.0

- old
+ new

@@ -29,11 +29,15 @@ def path [Star.configuration.location, @folder, @name].compact.join('/') end def store(tmp_file) - Star.remote? ? store_remote(tmp_file) : store_local(tmp_file) + if Star.remote? + retry_on_error {store_remote tmp_file} + else + store_local(tmp_file) + end end def delete Star.remote? ? delete_remote : delete_local end @@ -45,9 +49,18 @@ def remote_path URI.escape path end private + + def retry_on_error + yield + rescue Net::HTTPFatalError => e + raise if @retried + sleep 5 + @retried = true + retry + end def store_remote(tmp_file) timestamp = Time.now.utc.strftime "%a, %d %b %Y %H:%M:%S UTC" signature = sign "PUT\n\n#{@content_type}\n#{timestamp}" ::File.open(tmp_file) do |body|