1+ require 'net/smtp'
2+
13# frozen_string_literal: true
24
35# Health check configuration
68OkComputer . check_in_parallel = true
79
810class AlmaPatronCheck < OkComputer ::Check
9- TEST_PATRON_ID = '[email protected] ' 11+ TEST_PATRON_ID = '[email protected] ' . freeze 1012
1113 def check
1214 Alma ::User . find ( TEST_PATRON_ID )
@@ -19,8 +21,9 @@ def check
1921end
2022
2123# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
22- class CustomMailerCheck < OkComputer ::Check
23- require 'net/smtp'
24+ class MailConnectivityCheck < OkComputer ::Check
25+ OkComputer ::Registry . register 'mail-connectivity' , MailConnectivityCheck . new if ActionMailer ::Base . delivery_method == :smtp
26+
2427 # Check that the mail password is set
2528 def check
2629 settings = ActionMailer ::Base . smtp_settings
@@ -36,17 +39,21 @@ def check
3639 ) { mark_message 'Connection for smtp successful' }
3740 rescue Net ::SMTPAuthenticationError => e
3841 mark_failure
39- mark_message "Authentication error: #{ e . message } "
42+ Rails . logger . warn "SMTP authentication error: #{ e } "
43+ mark_message 'SMTP Error: Authentication failed. Check logs for more details'
4044 rescue Net ::SMTPServerBusy , Net ::SMTPSyntaxError , Net ::SMTPFatalError , Net ::SMTPUnknownError => e
4145 mark_failure
42- mark_message "SMTP error: #{ e . message } "
46+ Rails . logger . warn "SMTP Error: #{ e } "
47+ mark_message 'SMTP error. Check logs for more details'
4348 rescue IOError , Net ::ReadTimeout => e
4449 mark_failure
45- mark_message "Connection error: #{ e . message } "
50+ Rails . logger . warn "SMTP Timeout: #{ e } "
51+ mark_message 'SMTP Connection error: Timeout. Check logs for more details'
4652 rescue StandardError => e
4753 # Catch any other unexpected errors
4854 mark_failure
49- mark_message "An unexpected error occurred: #{ e . message } "
55+ Rails . logger . warn "SMTP standard error: #{ e } "
56+ mark_message 'SMTP ERROR: Could not connect. Check logs for more details'
5057 end
5158 end
5259end
@@ -57,7 +64,3 @@ def check
5764
5865# Ensure database migrations have been run.
5966OkComputer ::Registry . register 'database-migrations' , OkComputer ::ActiveRecordMigrationsCheck . new
60-
61- # Ensure connectivity to the mail system.
62- OkComputer ::Registry . register 'custom-mailer' , CustomMailerCheck . new
63- OkComputer ::Registry . register 'action-mailer' , OkComputer ::ActionMailerCheck . new
0 commit comments