I have a method inside my controller that I need execute inside delayed job method:
This is my order controller action:
class OrdersController < ApplicationController
def create
#code here
order = Order.first
Order.delay(queue: "order", priority: 1, run_at: 2.minutes.from_now).expire_order(order)
end
def template_expired_order(order)
#code here
end
end
This is my order model:
class Order
include Mongoid::Document
include Mongoid::Timestamps::Created
.
.
.
#delayed jobs method
def self.expire_order(order)
#code here
end
end
I want execute the controller method template_expired_order(order) when self.expire_order(order) method is executed or triggered or fired up.
How can I do it?
Thank you very much!
You should not put model-related code in the controller, especially if you want to run it in a background job. It’s not clear what template_expired_order does, but I would recommend putting it in the Order model and calling it directly on the order that gets pass into expired_order.