21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-06-09 11:04:28 +02:00
chexpire/app/services/notifier/resolver.rb

33 lines
771 B
Ruby
Raw Normal View History

2018-06-04 14:06:37 +02:00
module Notifier
class Resolver
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)
<= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
2018-06-04 14:06:37 +02:00
end
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)
.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