Con*_*ser 9 ruby ruby-on-rails sidekiq ruby-on-rails-4 rails-activejob
我想知道如何在resue块中访问ActiveJob执行参数,例如
def perform object
end
rescue_from Exception do |e|
if e.class != ActiveRecord::RecordNotFound
**job.arguments.first**
# do something
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢 !!
ago*_*orf 11
块arguments
内部可以rescue_from
:
rescue_from(StandardError) do |exception|
user = arguments[0]
post = arguments[1]
# ...
end
def perform(user, post)
# ...
end
Run Code Online (Sandbox Code Playgroud)
这也适用于回调(例如内部after_perform
).
我对此也不知道,然后只是决定尝试在块self
内使用rescue_from
,并且它起作用了。
rescue_from(StandardError) do |ex|
puts ex.inspect
puts self.job_id
# etc.
end
Run Code Online (Sandbox Code Playgroud)
作为旁注——永远不要救援Exception
:
为什么在 Ruby 中 `rescue Exception => e` 是一种不好的风格?
归档时间: |
|
查看次数: |
3362 次 |
最近记录: |