aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-07-27 07:41:41 +0200
committerRobert2017-07-27 07:41:41 +0200
commit96a6ae08191b465a91b285cf157223c0a898ed5d (patch)
treeaa45274f521b37fc3f5d12f03839f87273c4dbfb
parent9b97b8728a1d3714147591e4facacad097f2a155 (diff)
downloadchouette-core-96a6ae08191b465a91b285cf157223c0a898ed5d.tar.bz2
Refs: #3507@0.25h; Added information to retry callbacks in RetryService (for logging)
-rw-r--r--app/services/retry_service.rb4
-rw-r--r--spec/services/retry_service_spec.rb7
2 files changed, 8 insertions, 3 deletions
diff --git a/app/services/retry_service.rb b/app/services/retry_service.rb
index 0b8f5447b..55e2585ef 100644
--- a/app/services/retry_service.rb
+++ b/app/services/retry_service.rb
@@ -11,8 +11,8 @@ class RetryService
def execute &blk
status, result = execute_protected blk
return [status, result] if status == :ok
- @intervals.each do | interval |
- @failure_callback.try(:call)
+ @intervals.each_with_index do | interval, retry_count |
+ @failure_callback.try(:call, result, retry_count.succ)
sleep interval
status, result = execute_protected blk
return [status, result] if status == :ok
diff --git a/spec/services/retry_service_spec.rb b/spec/services/retry_service_spec.rb
index 93788c9ae..0ab9ddef9 100644
--- a/spec/services/retry_service_spec.rb
+++ b/spec/services/retry_service_spec.rb
@@ -67,12 +67,17 @@ RSpec.describe RetryService do
@failures = 0
@count = 0
expect( subject ).to receive(:sleep).with(2)
- subject.register_failure_callback { @failures += 1 }
+ subject.register_failure_callback { |reason, count| @reason=reason; @callback_count=count; @failures += 1 }
end
it 'succeeds the second time and calls the failure_callback once' do
subject.execute{ succeed_later(RetryService::Retry){ 42 } }
expect( @failures ).to eq(1)
end
+ it '... and the failure is passed into the callback' do
+ subject.execute{ succeed_later(RetryService::Retry){ 42 } }
+ expect( @reason ).to be_a(RetryService::Retry)
+ expect( @callback_count ).to eq(1)
+ end
end
context 'failure callback twice' do