1. 程式人生 > >Rails 異常處理 && 性能

Rails 異常處理 && 性能

use exceptio method call fill http 分享 del art


Rails 異常處理 的多種處理方法



1. routes match ‘*path‘, via: :all, to: ‘controller#action‘



2. application.rb 的 exception_app

    # application.rb
    config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
    config.action_dispatch.rescue_responses["ActionController::RoutingError"] = :not_found
    config.action_dispatch.rescue_responses["ActionController::BadRequest"] = :bad_request




3. exception_notification config/environments/

  #異常郵件通知
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.163.com",
    :port => 25,
    :domain => "163.com",
    :authentication => :login,
    :user_name => "[email protected]
/* */", :password => "******" } config.middleware.use ExceptionNotifier, :email_prefix => "[fgcc程序發生異常]", :sender_address => %{"異常通知" <[email protected]>}, :exception_recipients => [email protected]}





4. Slack & exception_notification

    # Gemfile
    # Slack api 封裝
    gem 'slack-notifier'
    # 異常監控
    gem 'exception_notification'


ruby 文件性能分析


profiler



Web 項目日誌分析request-log-analyzer

gem install request-log-analyzer
request-log-analyzer log/file.log

技術分享
Snip20151208_2.png


代碼分析 gem rubycritic
技術分享







rubocop

Rails 異常處理 &amp;&amp; 性能