aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-08-25 12:14:29 +0200
committerTeddy Wing2017-08-25 12:14:29 +0200
commit166b53305e41c51f4b401514a5ec2d828788a2cd (patch)
tree5b87863e3937eb4c990fc52dbbf770509cb3345a /app
parent36770fc9e7a4a8fe72d6bf7f2bc0dc328183e6fe (diff)
downloadchouette-core-166b53305e41c51f4b401514a5ec2d828788a2cd.tar.bz2
Remove `RetryService`
This is no longer being used as the `WorkbenchImportWorker` was refactored and it was decided that we don't want to enable retries for imports. For example, imagine you have an hour-long import that fails after 50 minutes. We retry three times and now we've wasted 2.5 hours of your time just to tell you that the import failed. Thus the decision was to remove it.
Diffstat (limited to 'app')
-rw-r--r--app/services/retry_service.rb63
1 files changed, 0 insertions, 63 deletions
diff --git a/app/services/retry_service.rb b/app/services/retry_service.rb
deleted file mode 100644
index 245dd32df..000000000
--- a/app/services/retry_service.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-require 'result'
-
-class RetryService
-
- Retry = Class.new(RuntimeError)
-
- # @param@ delays:
- # An array of delays that are used to retry after a sleep of the indicated
- # value in case of failed exceutions.
- # Once this array is exhausted the executen fails permanently
- #
- # @param@ rescue_from:
- # During execution all the excpetions from this array +plus RetryService::Retry+ are rescued from and
- # trigger just another retry after a `sleep` as indicated above.
- #
- # @param@ block:
- # This optional code is excuted before each retry, it is passed the result of the failed attempt, thus
- # an `Exception` and the number of execution already tried.
- def initialize( delays: [], rescue_from: [], logger: nil, &blk )
- @intervals = delays
- @logger = logger
- @registered_exceptions = Array(rescue_from) << Retry
- @failure_callback = blk
- end
-
- # @param@ blk:
- # The code to be executed it will be retried goverened by the `delay` passed into the initializer
- # as described there in case it fails with one of the predefined exceptions or `RetryService::Retry`
- #
- # Eventually it will return a `Result` object.
- def execute &blk
- result = execute_protected blk
- return result if result.ok?
- @intervals.each_with_index do | interval, retry_count |
- warn "retry #{retry_count + 1 }; sleeping #{interval}; cause: #{result.value.inspect}"
- sleep interval
- @failure_callback.try(:call, result.value, retry_count + 1)
- result = execute_protected blk
- return result if result.ok?
- end
- result
- end
-
-
- private
-
- def execute_protected blk
- result = blk.()
- return result if Result === result
- Result.ok(result)
- rescue Exception => e
- if @registered_exceptions.any?{ |re| e.is_a? re }
- Result.error(e)
- else
- raise
- end
- end
-
- def warn message
- return unless @logger
- @logger.try :warn, message
- end
-end