2018-06-04 14:06:37 +02:00
|
|
|
module Notifier
|
|
|
|
class Resolver
|
2018-08-01 17:06:20 +02:00
|
|
|
def notifications_expiring_soon
|
2018-06-04 14:06:37 +02:00
|
|
|
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
|
|
|
|
|
2018-08-01 17:06:20 +02:00
|
|
|
def checks_recurrent_failures(min_consecutive)
|
|
|
|
Check
|
|
|
|
.active
|
|
|
|
.consecutive_failures(min_consecutive)
|
|
|
|
.includes(:user)
|
|
|
|
.where.not(user: ignore_users)
|
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
|