mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-29 23:40:49 +02:00
Jérémy Lecour
815471da76
It's better to redure coupling between these classes and Rails. It gives liberty to provide configuration and other parameters depending on the context.
73 lines
1.7 KiB
Ruby
73 lines
1.7 KiB
Ruby
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
|
|
# License: GNU AGPL-3+ (see full text in LICENSE file)
|
|
|
|
module CheckProcessor
|
|
attr_reader :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)
|
|
|
|
sleep configuration.interval
|
|
end
|
|
end
|
|
@sync_finished_at = Time.now
|
|
end
|
|
|
|
# :nocov:
|
|
def resolvers
|
|
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
|
end
|
|
# :nocov:
|
|
|
|
def resolve_last_run_failed
|
|
scope.last_run_failed
|
|
end
|
|
|
|
def resolve_expire_long_term
|
|
scope
|
|
.where("DATE(domain_expires_at) >= DATE_ADD(CURDATE(), INTERVAL ? DAY)",
|
|
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_interval)
|
|
end
|
|
|
|
def resolve_unknown_expiry
|
|
scope.where("domain_expires_at IS NULL")
|
|
end
|
|
|
|
def resolve_all
|
|
scope
|
|
end
|
|
|
|
protected
|
|
|
|
def base_scope
|
|
Check
|
|
.active
|
|
.where("last_run_at IS NULL OR last_run_at < DATE_SUB(NOW(), INTERVAL 12 HOUR)")
|
|
end
|
|
|
|
# :nocov:
|
|
def scope
|
|
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
|
end
|
|
|
|
def process(_check)
|
|
fail NotImplementedError, "#{self.class.name} did not implemented method #{__callee__}"
|
|
end
|
|
# :nocov:
|
|
end
|