FIX: Ensure web hooks are retried at most 5 times

This commit is contained in:
Dan Ungureanu 2020-02-21 16:59:00 +02:00
parent 6ba326a9f4
commit cf0c6d5761
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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(