`
机器人
  • 浏览: 83287 次
  • 性别: Icon_minigender_2
  • 来自: Google
社区版块
存档分类
最新评论

rails-exception_notification插件的问题

阅读更多
传送门:
http://railsforum.com/viewtopic.php?id=35270

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

怎么异步,怎么新线程?怎么样不阻塞其它的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 楼 机器人 2009-11-03  
Hooopo 写道
你看看log是如何异步的...

不搞什么异步了,我简化化问题。分割线。
9 楼 Hooopo 2009-11-03  
你看看log是如何异步的...
8 楼 机器人 2009-11-03  
Hooopo 写道
哦....你不说清楚我怎么知道你说的设计问题是什么问题。。。

你不要管什么问题好好不好嘛,你就看一下怎么异步一下这个发信的操作,不让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
7 楼 Hooopo 2009-11-03  
哦....你不说清楚我怎么知道你说的设计问题是什么问题。。。
6 楼 Hooopo 2009-11-03  
>> u.delete_message((1000..1050).to_a)
  Message Update (16.0ms)   UPDATE `messages` SET status ='DELETED' WHERE ((from_id =98 OR to_id =98) AND id in(1000, 1001, 1002, 1003, 1004, 1005, 100
6, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034,
 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050)) 
=> 0

只有一条语句。。出错也是一个异常
5 楼 机器人 2009-11-03  
Hooopo 写道
引用
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:


我都说明了这是当前初设计 引起的问题。我现在只能一步一步的重构。
4 楼 Hooopo 2009-11-03  
引用
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

3 楼 机器人 2009-11-03  
Hooopo 写道
哈哈哈。。偶邪恶的路过

Hooopo兄弟,你有什么见解?
2 楼 Hooopo 2009-11-03  
哈哈哈。。偶邪恶的路过
1 楼 机器人 2009-11-03  

相关推荐

Global site tag (gtag.js) - Google Analytics