mirror of
https://github.com/Evolix/chexpire.git
synced 2024-06-14 13:34:29 +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:
parent
cedcc08f34
commit
815471da76
|
@ -6,10 +6,6 @@ class CheckDomainProcessor
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def configuration_key
|
|
||||||
"checks_domain"
|
|
||||||
end
|
|
||||||
|
|
||||||
def resolvers
|
def resolvers
|
||||||
%i[
|
%i[
|
||||||
resolve_last_run_failed
|
resolve_last_run_failed
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
module CheckProcessor
|
module CheckProcessor
|
||||||
attr_reader :configuration
|
attr_reader :configuration
|
||||||
|
|
||||||
def initialize(configuration = nil)
|
def initialize(configuration:, logger: NullLogger.new)
|
||||||
@configuration = configuration || default_configuration
|
@logger = logger
|
||||||
|
@configuration = configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_dates
|
def sync_dates
|
||||||
|
@sync_started_at = Time.now
|
||||||
resolvers.each do |resolver|
|
resolvers.each do |resolver|
|
||||||
public_send(resolver).find_each(batch_size: 100).each do |check|
|
public_send(resolver).find_each(batch_size: 100).each do |check|
|
||||||
process(check)
|
process(check)
|
||||||
|
@ -16,6 +18,7 @@ module CheckProcessor
|
||||||
sleep configuration.interval
|
sleep configuration.interval
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@sync_finished_at = Time.now
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nocov:
|
# :nocov:
|
||||||
|
@ -65,15 +68,5 @@ module CheckProcessor
|
||||||
def process(_check)
|
def process(_check)
|
||||||
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def configuration_key
|
|
||||||
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
|
||||||
end
|
|
||||||
# :nocov:
|
# :nocov:
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def default_configuration
|
|
||||||
Rails.configuration.chexpire.fetch(configuration_key)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,10 +6,6 @@ class CheckSSLProcessor
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def configuration_key
|
|
||||||
"checks_ssl"
|
|
||||||
end
|
|
||||||
|
|
||||||
def resolvers
|
def resolvers
|
||||||
%i[
|
%i[
|
||||||
resolve_all
|
resolve_all
|
||||||
|
|
|
@ -7,13 +7,17 @@ namespace :checks do
|
||||||
|
|
||||||
desc "Refresh domains expiry dates"
|
desc "Refresh domains expiry dates"
|
||||||
task domain: :environment do
|
task domain: :environment do
|
||||||
process = CheckDomainProcessor.new
|
configuration = Rails.configuration.chexpire.fetch("checks_domain")
|
||||||
|
|
||||||
|
process = CheckDomainProcessor.new(configuration: configuration)
|
||||||
process.sync_dates
|
process.sync_dates
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Refresh SSL expiry dates"
|
desc "Refresh SSL expiry dates"
|
||||||
task ssl: :environment do
|
task ssl: :environment do
|
||||||
process = CheckSSLProcessor.new
|
configuration = Rails.configuration.chexpire.fetch("checks_ssl")
|
||||||
|
|
||||||
|
process = CheckSSLProcessor.new(configuration: configuration)
|
||||||
process.sync_dates
|
process.sync_dates
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,8 @@ require "test_helper"
|
||||||
|
|
||||||
class CheckDomainProcessorTest < ActiveSupport::TestCase
|
class CheckDomainProcessorTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@processor = CheckDomainProcessor.new
|
configuration = Rails.configuration.chexpire.fetch("checks_domain")
|
||||||
|
@processor = CheckDomainProcessor.new(configuration: configuration)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "process WhoisSyncJob for domain checks" do
|
test "process WhoisSyncJob for domain checks" do
|
||||||
|
|
|
@ -9,10 +9,6 @@ class CheckDummyProcessor
|
||||||
base_scope
|
base_scope
|
||||||
end
|
end
|
||||||
|
|
||||||
def configuration_key
|
|
||||||
"checks_dummy"
|
|
||||||
end
|
|
||||||
|
|
||||||
def resolvers
|
def resolvers
|
||||||
%i[
|
%i[
|
||||||
resolve_expire_short_term
|
resolve_expire_short_term
|
||||||
|
@ -23,7 +19,8 @@ end
|
||||||
|
|
||||||
class CheckProcessorTest < ActiveSupport::TestCase
|
class CheckProcessorTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@processor = CheckDummyProcessor.new
|
configuration = Rails.configuration.chexpire.fetch("checks_dummy")
|
||||||
|
@processor = CheckDummyProcessor.new(configuration: configuration)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "resolve_last_run_failed includes already and never succeeded" do
|
test "resolve_last_run_failed includes already and never succeeded" do
|
||||||
|
@ -119,7 +116,7 @@ class CheckProcessorTest < ActiveSupport::TestCase
|
||||||
configuration.expect(:interval, 0.000001)
|
configuration.expect(:interval, 0.000001)
|
||||||
end
|
end
|
||||||
|
|
||||||
processor = CheckDummyProcessor.new(configuration)
|
processor = CheckDummyProcessor.new(configuration: configuration)
|
||||||
|
|
||||||
mock = Minitest::Mock.new
|
mock = Minitest::Mock.new
|
||||||
assert_stub = lambda { |actual_time|
|
assert_stub = lambda { |actual_time|
|
||||||
|
|
|
@ -5,7 +5,8 @@ require "test_helper"
|
||||||
|
|
||||||
class CheckSSLProcessorTest < ActiveSupport::TestCase
|
class CheckSSLProcessorTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@processor = CheckSSLProcessor.new
|
configuration = Rails.configuration.chexpire.fetch("checks_ssl")
|
||||||
|
@processor = CheckSSLProcessor.new(configuration: configuration)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "process SSLSyncJob for ssl checks" do
|
test "process SSLSyncJob for ssl checks" do
|
||||||
|
|
Loading…
Reference in a new issue