discourse/app/jobs/scheduled/admin_problems.rb
Bianca Nenciu cc18a99105
FEATURE: Add new notification for admin problems (#21287)
Add new notification for admin problems to replace old PM-based flow.
2023-05-03 19:35:22 +03:00

37 lines
911 B
Ruby

# frozen_string_literal: true
module Jobs
class AdminProblems < ::Jobs::Scheduled
every 30.minutes
def execute(args)
Notification
.where(notification_type: Notification.types[:admin_problems])
.where("created_at < ?", 7.days.ago)
.destroy_all
return if !persistent_problems?
notified_user_ids =
Notification.where(notification_type: Notification.types[:admin_problems]).pluck(:user_id)
users = Group[:admins].users.where.not(id: notified_user_ids)
users.each do |user|
Notification.create!(
notification_type: Notification.types[:admin_problems],
user_id: user.id,
data: "{}",
)
end
end
private
def persistent_problems?
problems_started_at = AdminDashboardData.problems_started_at
problems_started_at && problems_started_at < 2.days.ago
end
end
end