21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-05 02:05:09 +02:00
chexpire/app/services/notifier/resolver.rb
2018-06-05 15:24:44 +02:00

33 lines
802 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.delay 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