diff --git a/app/jobs/scheduled/poll_mailbox.rb b/app/jobs/scheduled/poll_mailbox.rb index 28186c01dd..9a69f14094 100644 --- a/app/jobs/scheduled/poll_mailbox.rb +++ b/app/jobs/scheduled/poll_mailbox.rb @@ -80,6 +80,7 @@ module Jobs client_message else + mark_as_errored! Discourse.handle_job_exception(e, error_context(@args, "Unrecognized error type when processing incoming email", mail: mail_string)) end end @@ -94,8 +95,21 @@ module Jobs end end rescue Net::POPAuthenticationError => e + mark_as_errored! Discourse.handle_job_exception(e, error_context(@args, "Signing in to poll incoming email")) end + POLL_MAILBOX_ERRORS_KEY ||= "poll_mailbox_errors".freeze + + def self.errors_in_past_24_hours + $redis.zremrangebyscore(POLL_MAILBOX_ERRORS_KEY, 0, 24.hours.ago.to_i) + $redis.zcard(POLL_MAILBOX_ERRORS_KEY).to_i + end + + def mark_as_errored! + now = Time.now.to_i + $redis.zadd(POLL_MAILBOX_ERRORS_KEY, now, now.to_s) + end + end end diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index e2a130053a..9f2bfad63e 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -63,7 +63,7 @@ class AdminDashboardData :send_consumer_email_check, :title_check, :site_description_check, :site_contact_username_check, :notification_email_check, :subfolder_ends_in_slash_check, - :pop3_polling_configuration + :pop3_polling_configuration, :email_polling_errored_recently add_problem_check do sidekiq_check || queue_size_check @@ -210,4 +210,9 @@ class AdminDashboardData POP3PollingEnabledSettingValidator.new.error_message if SiteSetting.pop3_polling_enabled end + def email_polling_errored_recently + errors = Jobs::PollMailbox.errors_in_past_24_hours + I18n.t('dashboard.email_polling_errored_recently', count: errors) if errors > 0 + end + end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 5575248840..fc3a90218c 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -781,6 +781,9 @@ en: site_contact_username_warning: "Enter the name of a friendly staff user account to send important automated messages from. Update site_contact_username in Site Settings." notification_email_warning: "Notification emails are not being sent from a valid email address on your domain; email delivery will be erratic and unreliable. Please set notification_email to a valid local email address in Site Settings." subfolder_ends_in_slash: "Your subfolder setup is incorrect; the DISCOURSE_RELATIVE_URL_ROOT ends in a slash." + email_polling_errored_recently: + one: "Email polling has generated an error in the past 24 hours. Look at the logs for more details." + other: "Email polling has generated %{count} errors in the past 24 hours. Look at the logs for more details." site_settings: censored_words: "Words that will be automatically replaced with ■■■■"