diff --git a/app/services/check_processor.rb b/app/services/check_processor.rb index abe087c..9492505 100644 --- a/app/services/check_processor.rb +++ b/app/services/check_processor.rb @@ -28,14 +28,14 @@ module CheckProcessor def resolve_expire_long_term scope .where("DATE(domain_expires_at) >= DATE_ADD(CURDATE(), INTERVAL ? DAY)", - configuration.long_term) + configuration.long_term_interval) .where("DATEDIFF(domain_expires_at, CURDATE()) MOD ? = 0", configuration.long_term_frequency) end def resolve_expire_short_term scope.where("DATE(domain_expires_at) < DATE_ADD(CURDATE(), INTERVAL ? DAY)", - configuration.long_term) + configuration.long_term_interval) end def resolve_unknown_expiry @@ -71,12 +71,6 @@ module CheckProcessor private def default_configuration - config = Rails.configuration.chexpire.fetch(configuration_key, {}) - - OpenStruct.new( - interval: config.fetch("interval") { 0.00 }, - long_term: config.fetch("long_term") { 60 }, - long_term_frequency: config.fetch("long_term_frequency") { 10 }, - ) + Rails.configuration.chexpire.fetch(configuration_key) end end diff --git a/app/services/notifier/processor.rb b/app/services/notifier/processor.rb index 2d7fe15..e2893a4 100644 --- a/app/services/notifier/processor.rb +++ b/app/services/notifier/processor.rb @@ -1,5 +1,5 @@ module Notifier - Configuration = Struct.new(:interval, :failure_days) + Configuration = Struct.new(:interval, :consecutive_failures) class Processor attr_reader :configuration @@ -24,9 +24,7 @@ module Notifier end def process_recurrent_failures - resolver.resolve_check_failed.find_each do |notification| - next unless should_notify_for_recurrent_failures?(notification) - + resolver.resolve_check_failed(configuration.consecutive_failures).find_each do |notification| notifier_channel_for(notification).notify(:recurrent_failures, notification) sleep configuration.interval @@ -40,17 +38,12 @@ module Notifier Configuration.new( config.fetch("interval") { 0.00 }, - config.fetch("failures_days") { 3 }, + config.fetch("consecutive_failures") { 3 }, ) end def notifier_channel_for(notification) channels.fetch(notification.channel.to_sym) end - - def should_notify_for_recurrent_failures?(_notification) - true - # TODO: dependent of logs consecutive failures - end end end diff --git a/test/services/check_processor_test.rb b/test/services/check_processor_test.rb index d5c1387..5804366 100644 --- a/test/services/check_processor_test.rb +++ b/test/services/check_processor_test.rb @@ -109,8 +109,8 @@ class CheckProcessorTest < ActiveSupport::TestCase create_list(:check, 3, :expires_next_week) configuration = Minitest::Mock.new - 2.times do configuration.expect(:long_term, 60) end - configuration.expect(:long_term_frequency, 10) + 2.times do configuration.expect(:long_term_interval, 300) end + configuration.expect(:long_term_frequency, 4) 3.times do configuration.expect(:interval, 0.000001) diff --git a/test/services/notifier/processor_test.rb b/test/services/notifier/processor_test.rb index c0aeaf6..c44ffda 100644 --- a/test/services/notifier/processor_test.rb +++ b/test/services/notifier/processor_test.rb @@ -23,7 +23,9 @@ module Notifier test "#process_recurrent_failures respects the interval configuration between sends" do create_list(:notification, 3, :email, check: build(:check, :last_runs_failed)) - test_interval_respected(:process_recurrent_failures, 3) + test_interval_respected(:process_recurrent_failures, 3) do |configuration| + configuration.expect(:consecutive_failures, 4) + end end private @@ -34,6 +36,9 @@ module Notifier count_expected.times do configuration.expect(:interval, 0.000001) end + + yield configuration if block_given? + processor = Processor.new(configuration) mock = Minitest::Mock.new