21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-02 17:00:49 +02:00
chexpire/app/services/notifier/resolver.rb
Jérémy Lecour 830b978626
Rename Notifications.delay to .interval
From French to English "interval" is a better translation than "delay".
It's supposed to mean a number of days between two dates.
2018-07-02 09:52:49 +02:00

33 lines
805 B
Ruby

module Notifier
class Resolver
def resolve_expires_soon
scope
.where("checks.domain_expires_at >= CURDATE()")
.where("DATE(checks.domain_expires_at)
<= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
end
def resolve_check_failed
# Only gets here the checks having its last run in error
# Logical rules are in plain ruby inside processor
scope
.includes(check: :logs)
.merge(Check.last_run_failed)
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