From cf0c6d5761a0430ec8d5d2875008dd7487865d64 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 21 Feb 2020 16:59:00 +0200 Subject: [PATCH] FIX: Ensure web hooks are retried at most 5 times --- app/jobs/regular/emit_web_hook_event.rb | 1 + spec/jobs/emit_web_hook_event_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb index 74c8153ad69..ffd8e410ec5 100644 --- a/app/jobs/regular/emit_web_hook_event.rb +++ b/app/jobs/regular/emit_web_hook_event.rb @@ -93,6 +93,7 @@ module Jobs @retry_count += 1 return if @retry_count > MAX_RETRY_COUNT delay = RETRY_BACKOFF**(@retry_count - 1) + @arguments[:retry_count] = @retry_count ::Jobs.enqueue_in(delay.minutes, :emit_web_hook_event, @arguments) end end diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb index f2200df9121..e87d6b7c7c4 100644 --- a/spec/jobs/emit_web_hook_event_spec.rb +++ b/spec/jobs/emit_web_hook_event_spec.rb @@ -90,6 +90,19 @@ describe Jobs::EmitWebHookEvent do end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(1) end + it 'retries at most 5 times' do + Jobs.run_immediately! + + expect(Jobs::EmitWebHookEvent::MAX_RETRY_COUNT + 1).to eq(5) + + expect do + subject.execute( + web_hook_id: post_hook.id, + event_type: described_class::PING_EVENT + ) + end.to change { WebHookEvent.count }.by(Jobs::EmitWebHookEvent::MAX_RETRY_COUNT + 1) + end + it 'does not retry for more than maximum allowed times' do expect do subject.execute(