Skip to content

Commit

Permalink
Merge pull request #120 from lbeder/configure-maximum-amount-of-retries
Browse files Browse the repository at this point in the history
Make sidekiq maximum_amount_of_retries configurable
  • Loading branch information
lbeder authored Mar 29, 2024
2 parents d828b9c + b1a2983 commit 8c53cd9
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 16 deletions.
102 changes: 93 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ Lint/RequireRangeParentheses:
Lint/UselessRescue:
Enabled: true

Lint/MixedCaseRange:
Enabled: true

Lint/RedundantRegexpQuantifiers:
Enabled: true

Naming/BlockForwarding:
Enabled: true

Expand Down Expand Up @@ -446,6 +452,30 @@ Style/RedundantInitialize:
Style/RedundantStringEscape:
Enabled: true

Style/ExactRegexpMatch:
Enabled: true

Style/RedundantArrayConstructor:
Enabled: true

Style/RedundantCurrentDirectoryInPath:
Enabled: true

Style/RedundantFilterChain:
Enabled: true

Style/RedundantRegexpArgument:
Enabled: true

Style/RedundantRegexpConstructor:
Enabled: true

Style/ReturnNilInPredicateMethodDefinition:
Enabled: true

Style/YAMLFileRead:
Enabled: true

RSpec/ExampleLength:
Enabled: false

Expand Down Expand Up @@ -497,12 +527,6 @@ RSpec/SubjectDeclaration:
RSpec/VerifiedDoubleReference:
Enabled: true

RSpec/FactoryBot/ConsistentParenthesesStyle:
Enabled: true

RSpec/FactoryBot/SyntaxMethods:
Enabled: true

RSpec/Rails/AvoidSetupHook:
Enabled: true

Expand All @@ -518,9 +542,6 @@ RSpec/DuplicatedMetadata:
RSpec/PendingWithoutReason:
Enabled: true

RSpec/FactoryBot/FactoryNameStyle:
Enabled: true

RSpec/RedundantAround:
Enabled: true

Expand All @@ -533,6 +554,39 @@ RSpec/Rails/MinitestAssertions:
RSpec/Rails/TravelAround:
Enabled: true

RSpec/BeEmpty:
Enabled: true

RSpec/ContainExactly:
Enabled: true

RSpec/EmptyMetadata:
Enabled: true

RSpec/Eq:
Enabled: true

RSpec/IndexedLet:
Enabled: false

RSpec/MatchArray:
Enabled: true

RSpec/MetadataStyle:
Enabled: true

RSpec/ReceiveMessages:
Enabled: true

RSpec/SpecFilePathFormat:
Enabled: false

RSpec/SpecFilePathSuffix:
Enabled: true

RSpec/Rails/NegationBeValid:
Enabled: true

Capybara/NegationMatcher:
Enabled: true

Expand All @@ -547,3 +601,33 @@ Capybara/SpecificMatcher:

Capybara/MatchStyle:
Enabled: true

Capybara/ClickLinkOrButtonStyle:
Enabled: true

Capybara/RSpec/HaveSelector:
Enabled: true

Capybara/RSpec/PredicateMatcher:
Enabled: true

FactoryBot/ConsistentParenthesesStyle:
Enabled: true

FactoryBot/SyntaxMethods:
Enabled: true

FactoryBot/FactoryNameStyle:
Enabled: true

FactoryBot/AssociationStyle:
Enabled: true

FactoryBot/FactoryAssociationWithStrategy:
Enabled: true

FactoryBot/IdSequence:
Enabled: true

FactoryBot/RedundantFactoryOption:
Enabled: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 12.1.0 (2024-03-29)

- Make sidekiq maximum_amount_of_retries configurable

## 12.0.0 (2024-03-23)

- Use "SELECT 1" to check for DB connectivity and liveness (thanks to @jayceekay)
Expand Down
12 changes: 9 additions & 3 deletions lib/health_monitor/providers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class Configuration < Base::Configuration
DEFAULT_QUEUES_SIZE = 100
DEFAULT_RETRY_CHECK = 20

attr_accessor :maximum_amount_of_retries
attr_reader :queues

def initialize(provider)
super(provider)

@maximum_amount_of_retries = DEFAULT_RETRY_CHECK

@queues = {}
@queues[DEFAULT_QUEUE_NAME] = { latency: DEFAULT_LATENCY_TIMEOUT, queue_size: DEFAULT_QUEUES_SIZE }
end
Expand Down Expand Up @@ -96,10 +99,13 @@ def check_queue_size!
end

def check_amount_of_retries!
maximum_amount_of_retries = ::HealthMonitor::Providers::Sidekiq::Configuration::DEFAULT_RETRY_CHECK
jobs_over_limit = ::Sidekiq::RetrySet.new.select { |job| job.item['retry_count'] >= maximum_amount_of_retries }
jobs_over_limit = ::Sidekiq::RetrySet.new.select do |job|
job.item['retry_count'] >= configuration.maximum_amount_of_retries
end

return unless jobs_over_limit.any?

raise "amount of retries for a job is greater than #{maximum_amount_of_retries}" if jobs_over_limit.any?
raise "amount of retries for a job is greater than #{configuration.maximum_amount_of_retries}"
end

def check_redis!
Expand Down
2 changes: 1 addition & 1 deletion lib/health_monitor/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module HealthMonitor
VERSION = '12.0.0'
VERSION = '12.1.0'
end
2 changes: 1 addition & 1 deletion spec/lib/health_monitor/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CustomProvider < HealthMonitor::Providers::Base
it 'accepts' do
expect {
subject.add_custom_provider(CustomProvider)
}.to change(subject, :providers).to(Array.new([CustomProvider]))
}.to change(subject, :providers).to([CustomProvider])
end

it 'returns CustomProvider class' do
Expand Down
3 changes: 1 addition & 2 deletions spec/support/providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def stub_sidekiq
allow_any_instance_of(Sidekiq::Workers).to receive(:size).and_return(5)

queue = instance_double(Sidekiq::Queue)
allow(queue).to receive(:latency).and_return(5)
allow(queue).to receive(:size).and_return(5)
allow(queue).to receive_messages(latency: 5, size: 10)
allow(Sidekiq::Queue).to receive(:new).and_return(queue)

retry_set = instance_double(Sidekiq::RetrySet)
Expand Down

0 comments on commit 8c53cd9

Please sign in to comment.