21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-05 10:15:09 +02:00
chexpire/app/services/notifier/resolver.rb
Colin Darie ea610ee185
Notifications grouped of checks in error to user email.
This is not dependent of Notificatioon model.
2018-08-01 23:09:08 +02:00

33 lines
771 B
Ruby

module Notifier
class Resolver
def notifications_expiring_soon
scope
.where("checks.domain_expires_at >= CURDATE()")
.where("DATE(checks.domain_expires_at)
<= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
end
def checks_recurrent_failures(min_consecutive)
Check
.active
.consecutive_failures(min_consecutive)
.includes(:user)
.where.not(user: ignore_users)
end
private
def scope
Notification
.includes(:check)
.where(status: [:pending, :failed])
.merge(Check.active)
.where.not(checks: { user: ignore_users })
end
def ignore_users
@ignore_users ||= User.notifications_disabled.pluck(:id)
end
end
end