21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-01 16:30:49 +02:00
chexpire/app/services/notifier/resolver.rb
2018-08-02 00:29:53 +02:00

36 lines
947 B
Ruby

# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Jeremy Lecour <jlecour@evolix.fr>, 2018 Evolix <info@evolix.fr>
# License: GNU AGPL-3+ (see full text in LICENSE file)
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