lib/flydata/helpers.rb in flydata-0.1.3 vs lib/flydata/helpers.rb in flydata-0.1.4
- old
+ new
@@ -73,7 +73,24 @@
end
def flydata_conf_file
File.join(FLYDATA_HOME, 'flydata.conf')
end
+
+ # Retry the given block if +exception+ happens
+ def retry_on(exception = StandardError, try_count = 3, interval = 1.0)
+ count = 0
+ begin
+ count += 1
+ yield
+ rescue exception
+ if count < try_count
+ sleep interval
+ interval *= 2
+ retry
+ else
+ raise
+ end
+ end
+ end
end
end