21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-04-30 07:50:49 +02:00

CheckProcessor configuration is always passed

It's better to redure coupling between these classes and Rails.
It gives liberty to provide configuration and other parameters
depending on the context.
This commit is contained in:
Jérémy Lecour 2018-08-29 12:14:34 +02:00 committed by Jérémy Lecour
parent cedcc08f34
commit 815471da76
7 changed files with 18 additions and 30 deletions

View file

@ -6,10 +6,6 @@ class CheckDomainProcessor
protected
def configuration_key
"checks_domain"
end
def resolvers
%i[
resolve_last_run_failed

View file

@ -4,11 +4,13 @@
module CheckProcessor
attr_reader :configuration
def initialize(configuration = nil)
@configuration = configuration || default_configuration
def initialize(configuration:, logger: NullLogger.new)
@logger = logger
@configuration = configuration
end
def sync_dates
@sync_started_at = Time.now
resolvers.each do |resolver|
public_send(resolver).find_each(batch_size: 100).each do |check|
process(check)
@ -16,6 +18,7 @@ module CheckProcessor
sleep configuration.interval
end
end
@sync_finished_at = Time.now
end
# :nocov:
@ -65,15 +68,5 @@ module CheckProcessor
def process(_check)
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
end
def configuration_key
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
end
# :nocov:
private
def default_configuration
Rails.configuration.chexpire.fetch(configuration_key)
end
end

View file

@ -6,10 +6,6 @@ class CheckSSLProcessor
protected
def configuration_key
"checks_ssl"
end
def resolvers
%i[
resolve_all

View file

@ -7,13 +7,17 @@ namespace :checks do
desc "Refresh domains expiry dates"
task domain: :environment do
process = CheckDomainProcessor.new
configuration = Rails.configuration.chexpire.fetch("checks_domain")
process = CheckDomainProcessor.new(configuration: configuration)
process.sync_dates
end
desc "Refresh SSL expiry dates"
task ssl: :environment do
process = CheckSSLProcessor.new
configuration = Rails.configuration.chexpire.fetch("checks_ssl")
process = CheckSSLProcessor.new(configuration: configuration)
process.sync_dates
end
end

View file

@ -5,7 +5,8 @@ require "test_helper"
class CheckDomainProcessorTest < ActiveSupport::TestCase
setup do
@processor = CheckDomainProcessor.new
configuration = Rails.configuration.chexpire.fetch("checks_domain")
@processor = CheckDomainProcessor.new(configuration: configuration)
end
test "process WhoisSyncJob for domain checks" do

View file

@ -9,10 +9,6 @@ class CheckDummyProcessor
base_scope
end
def configuration_key
"checks_dummy"
end
def resolvers
%i[
resolve_expire_short_term
@ -23,7 +19,8 @@ end
class CheckProcessorTest < ActiveSupport::TestCase
setup do
@processor = CheckDummyProcessor.new
configuration = Rails.configuration.chexpire.fetch("checks_dummy")
@processor = CheckDummyProcessor.new(configuration: configuration)
end
test "resolve_last_run_failed includes already and never succeeded" do
@ -119,7 +116,7 @@ class CheckProcessorTest < ActiveSupport::TestCase
configuration.expect(:interval, 0.000001)
end
processor = CheckDummyProcessor.new(configuration)
processor = CheckDummyProcessor.new(configuration: configuration)
mock = Minitest::Mock.new
assert_stub = lambda { |actual_time|

View file

@ -5,7 +5,8 @@ require "test_helper"
class CheckSSLProcessorTest < ActiveSupport::TestCase
setup do
@processor = CheckSSLProcessor.new
configuration = Rails.configuration.chexpire.fetch("checks_ssl")
@processor = CheckSSLProcessor.new(configuration: configuration)
end
test "process SSLSyncJob for ssl checks" do