Commit 7575e600 authored by PiTrem's avatar PiTrem
Browse files

send mail to define emails when production app restarted

to emails from ENV

do not send mail if rails console started
wait 1 min and check before adding new job to avoid
duplicate email when all apps are restarted(passenger+worker)
parent 81f15eb5
class AppRestartMailJob < ActiveJob::Base
queue_as :default
def perform
AppRestartMailer.send_mail&.deliver_now
end
end
class AppRestartMailer < ActionMailer::Base
default from: ENV['DEVISE_SENDER'] || 'eln'
def text_content
"The application was restarted.\n#{revision}"
end
def revision
if File.exist?('../../revisions.log')
`tail -n 1 ../../revisions.log`
end
end
def send_mail
unless ENV['ADM_EMAILS'].blank?
mail(to: ENV['ADM_EMAILS'], subject: "Rails app restarted") do |format|
format.text { render plain: text_content }
end
end
end
end
......@@ -89,7 +89,11 @@ Rails.application.configure do
:enable_starttls_auto => ENV['SMTP_TLS'] && ENV['SMTP_TLS'].match(/true/),
:openssl_verify_mode => ENV['SMTP_SSL_MODE']
}
config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 react ] --plugins [ transform-object-rest-spread ] ] -g uglifyify -p bundle-collapser/plugin "
config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 react ] --plugins [ transform-object-rest-spread ] ] -g uglifyify -p bundle-collapser/plugin "
unless defined?(Rails::Console)
config.after_initialize do
AppRestartMailJob.set(wait: 1.minute).perform_later if Delayed::Job.where("handler like ?", "%AppRestartMailJob%").empty?
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment