mirror of
https://github.com/Evolix/chexpire.git
synced 2024-07-01 21:42:52 +02:00
36 lines
947 B
Ruby
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
|