FEATURE: notify admins if problems have been reported on the dashboard for a while
This commit is contained in:
parent
c948d53d91
commit
9c934e27be
|
@ -5,6 +5,13 @@ module Jobs
|
|||
every 30.minutes
|
||||
|
||||
def execute(args)
|
||||
problems_started_at = AdminDashboardData.problems_started_at
|
||||
if problems_started_at && problems_started_at < 2.days.ago
|
||||
# If there have been problems reported on the dashboard for a while,
|
||||
# send a message to admins no more often than once per week.
|
||||
GroupMessage.create(Group[:admins].name, :dashboard_problems, {limit_once_per: 7.days.to_i})
|
||||
end
|
||||
|
||||
stats = AdminDashboardData.fetch_stats
|
||||
set_cache(AdminDashboardData, stats)
|
||||
stats
|
||||
|
|
|
@ -50,7 +50,33 @@ class AdminDashboardData
|
|||
AdminDashboardData.problem_messages.each do |i18n_key|
|
||||
problems << AdminDashboardData.problem_message_check(i18n_key)
|
||||
end
|
||||
problems.compact
|
||||
problems.compact!
|
||||
|
||||
if problems.empty?
|
||||
self.class.clear_problems_started
|
||||
else
|
||||
self.class.set_problems_started
|
||||
end
|
||||
|
||||
problems
|
||||
end
|
||||
|
||||
def self.problems_started_key
|
||||
"dash-problems-started-at"
|
||||
end
|
||||
|
||||
def self.set_problems_started
|
||||
existing_time = $redis.get(problems_started_key)
|
||||
$redis.setex(problems_started_key, 14.days.to_i, existing_time || Time.zone.now.to_s)
|
||||
end
|
||||
|
||||
def self.clear_problems_started
|
||||
$redis.del problems_started_key
|
||||
end
|
||||
|
||||
def self.problems_started_at
|
||||
s = $redis.get(problems_started_key)
|
||||
s ? Time.zone.parse(s) : nil
|
||||
end
|
||||
|
||||
# used for testing
|
||||
|
|
|
@ -2044,6 +2044,13 @@ en:
|
|||
subject_template: "Downloading remote images disabled"
|
||||
text_body_template: "The `download_remote_images_to_local` setting was disabled because the disk space limit at `download_remote_images_threshold` was reached."
|
||||
|
||||
dashboard_problems:
|
||||
subject_template: "Problems have been found"
|
||||
text_body_template: |
|
||||
Some problems are being reported on your admin dashboard.
|
||||
|
||||
[Please review and fix them](%{base_url}/admin).
|
||||
|
||||
unsubscribe_link: |
|
||||
To stop receiving notifications for this particular topic, [click here](%{unsubscribe_url}). To unsubscribe from these emails, change your [user preferences](%{user_preferences_url})
|
||||
|
||||
|
|
Loading…
Reference in New Issue