ITeye博客

rails-exception_notification插件的问题

机器人 · 2009-11-03 11:42 · Markdown

传送门: http://railsforum.com/viewtopic.php?id=35270

怎么解决这个问题呢?有什么好办法吗? :oops:

怎么异步,怎么新线程?怎么样不阻塞其它的request?怎么样就不会搞死我的web server?

当然首先我认为这是当初设计时引起的问题,但是现在除了不重构代码,怎么hack这个plugin来解决这个问题呢?

================分割线============================= 根据下一站火星的看法,我决定不去考虑异步发信操作,新开ruby线程什么的。还是问题简单化。我决定不使用这个rails-exception_notification插件的发信操作了,我自己将500中的信息保存到数据库,然后再通过email定时来发送500邮件了。

小小的一点点hack这个异常处理的方法

    def rescue_action_in_public(exception)
      case exception
        when *self.class.exceptions_to_treat_as_404
          render_404

        else          
          render_500

          deliverer = self.class.exception_data
          data = case deliverer
            when nil then {}
            when Symbol then send(deliverer)
            when Proc then deliverer.call(self)
          end

          #ExceptionNotifier.deliver_exception_notification(exception, self,
            request, data)
          # TODO:这样做
          # SystemLog.create(".............................")
      end
    end

评论(10)

  1. #10 楼 · 机器人 · 2009-11-03 13:40

    Hooopo writes:

    你看看log是如何异步的...

    不搞什么异步了,我简化化问题。分割线。

  2. #9 楼 · Hooopo · 2009-11-03 13:11

    你看看log是如何异步的...

  3. #8 楼 · 机器人 · 2009-11-03 12:56

    Hooopo writes:

    哦....你不说清楚我怎么知道你说的设计问题是什么问题。。。

    你不要管什么问题好好不好嘛,你就看一下怎么异步一下这个发信的操作,不让currrent request wait:

        def rescue_action_in_public(exception)
          case exception
            when *self.class.exceptions_to_treat_as_404
              render_404
    
            else          
              render_500
    
              deliverer = self.class.exception_data
              data = case deliverer
                when nil then {}
                when Symbol then send(deliverer)
                when Proc then deliverer.call(self)
              end
    
              ExceptionNotifier.deliver_exception_notification(exception, self,
                request, data)
          end
        end
    
  4. #7 楼 · Hooopo · 2009-11-03 12:11

    哦....你不说清楚我怎么知道你说的设计问题是什么问题。。。

  5. #6 楼 · Hooopo · 2009-11-03 12:09

    u.delete_message((1000..1050).to_a)  只有一条语句。。出错也是一个异常 :wink:

  6. #5 楼 · 机器人 · 2009-11-03 12:07

    Hooopo writes:

    [quote]In my rails app,sometimes,user select all checkbox in a form,maybe 50+ record. in controller,if a 500 error happened.There will be 50+ times to send email. Bug sending email take some seconds. The exception_notification plugin will send email 50+ times[/quote]

    这个问题?一般不会产生50+个异常吧?比如删除多个checkbox:

    我都说明了这是当前初设计 引起的问题。我现在只能一步一步的重构。

  7. #4 楼 · Hooopo · 2009-11-03 12:05

    In my rails app,sometimes,user select all checkbox in a form,maybe 50+ record. in controller,if a 500 error happened.There will be 50+ times to send email. Bug sending email take some seconds. The exception_notification plugin will send email 50+ times

    这个问题?一般不会产生50+个异常吧?比如删除多个checkbox:

    class User < ActiveRecord::Base
    def delete_message(ids)
        Message.update_all(
          "status ='#{Message::STATUS_DELETED}'",
          "(from_id =#{self.id} OR to_id =#{self.id}) AND id in(#{ids.join(", ")})"
        )
      end
    end
    
    
    class MessageController < ApplicationController
    def delete
        if current_user.delete_message(params[:delete_ids])
          flash[:notice] = "删除成功!"
          redirect_to request.referer
        end
      end
    end
    
  8. #3 楼 · 机器人 · 2009-11-03 11:56

    Hooopo writes:

    哈哈哈。。偶邪恶的路过 8)

    Hooopo兄弟,你有什么见解?

  9. #2 楼 · Hooopo · 2009-11-03 11:53

    哈哈哈。。偶邪恶的路过 8)

  10. #1 楼 · 机器人 · 2009-11-03 11:53

评论功能维护中,当前仅展示历史评论。