2018-06-04 14:06:37 +02:00
|
|
|
module Notifier
|
|
|
|
class Resolver
|
|
|
|
def resolve_expires_soon
|
|
|
|
scope
|
|
|
|
.where("checks.domain_expires_at >= CURDATE()")
|
|
|
|
.where("DATE(checks.domain_expires_at)
|
2018-06-05 22:44:48 +02:00
|
|
|
<= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
|
2018-06-04 14:06:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_check_failed
|
|
|
|
# Only gets here the checks having its last run in error
|
|
|
|
# Logical rules are in plain ruby inside processor
|
|
|
|
scope
|
|
|
|
.includes(check: :logs)
|
2018-06-05 15:24:44 +02:00
|
|
|
.merge(Check.last_run_failed)
|
2018-06-04 14:06:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def scope
|
|
|
|
Notification
|
|
|
|
.includes(:check)
|
2018-06-05 15:24:44 +02:00
|
|
|
.where(status: [:pending, :failed])
|
|
|
|
.merge(Check.active)
|
2018-06-04 14:06:37 +02:00
|
|
|
.where.not(checks: { user: ignore_users })
|
|
|
|
end
|
|
|
|
|
|
|
|
def ignore_users
|
|
|
|
@ignore_users ||= User.notifications_disabled.pluck(:id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|