I have this job on my controller:
def action1
#code here
order = Order.find(params[:id])
Delayed::Job.enqueue(ExpiredMessage.new(order), 2, 2.days.from_now)
#code here
end
I have inside myapp/app/jobs a custom job inside a file called expired_message.rb with the next content:
class ExpiredMessage < Struct.new(:order)
def perform
#code to run here for example order.save
order.any_method
end
end
I want execute the code inside perform method only if order.status == "PA"
How can I run a hook before save the order to check if order.status == "PA" on my custom job?
Otherwise, if the order.status != “PA” I want delete the job before this job is executed.
Thank you very much!
If you want to check an object’s status from the database – call
reloadon it. Otherwise, just check it as you would any other object: