Rails 没有中间件的异常通知
Rails Exception Notification without middleware
我有一个 Rails 4 应用程序,它完全由 rails 运行ners over cron 从 whenever gem 生成。
如果 运行 期间发生任何异常,我希望得到通知。 exception_notification gem 仅 运行 作为机架中间件(仅限 Web 请求),因此它不处理 rails 运行 用户。
有什么想法吗?我希望通过电子邮件或 Slack 收到通知。
您可以在救援块中使用 ExceptionNotifier.notify_exception
来发送通知。
例如:
def rescue_exception(data)
yield
rescue => e
ExceptionNotifier.notify_exception(e, data: data)
end
every :hour do
rescue_exception(runner: 'SomeModel.some_method') do
runner "SomeModel.some_method"
end
end
请参考https://github.com/smartinez87/exception_notification#background-notifications。使用 data
哈希传递有关上下文的附加信息。
我有一个 Rails 4 应用程序,它完全由 rails 运行ners over cron 从 whenever gem 生成。
如果 运行 期间发生任何异常,我希望得到通知。 exception_notification gem 仅 运行 作为机架中间件(仅限 Web 请求),因此它不处理 rails 运行 用户。
有什么想法吗?我希望通过电子邮件或 Slack 收到通知。
您可以在救援块中使用 ExceptionNotifier.notify_exception
来发送通知。
例如:
def rescue_exception(data)
yield
rescue => e
ExceptionNotifier.notify_exception(e, data: data)
end
every :hour do
rescue_exception(runner: 'SomeModel.some_method') do
runner "SomeModel.some_method"
end
end
请参考https://github.com/smartinez87/exception_notification#background-notifications。使用 data
哈希传递有关上下文的附加信息。