Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access perform parameters in ActiveJob rescue

I am wondering on how do you access ActiveJob perform parameters in the resue block, such as

def perform object
end

rescue_from Exception do |e|
   if e.class != ActiveRecord::RecordNotFound
      **job.arguments.first** 
      # do something
   end
end

Thank You !!

like image 260
ConfusedUser Avatar asked Mar 16 '15 19:03

ConfusedUser


1 Answers

It is possible with arguments inside the rescue_from block:

rescue_from(StandardError) do |exception|
  user = arguments[0]
  post = arguments[1]
  # ...      
end

def perform(user, post)
  # ...
end

This also works for callbacks as well (e.g. inside after_perform).

like image 141
agorf Avatar answered Sep 28 '22 03:09

agorf