Well, it's something I was trying for a site where you can buy ads for your product once it's listed, but the ads wouldn't be created until I received a notification from Paypal telling the application that the payment was done. It's just a regular delayed job, only not automatically consumed but on demand.
It would go like this (just an example, not code from my actual project).
# ad_controller.rb
def new
@product = Product.find params[:product_id]
@job = @product.delay.create params[:ad]
# Code redirecting user to Paypal passing @job id
end
Then we would receive the notification.
# payment_notifications_controller.rb
def create
if params[:status] == 'Completed' then
job = Delayed::Job.find params[:custom][:job_id]
worker = Delayed::Worker.new
worker.run job
end
end
Again, this is just concept, not my actual code and you probably won't understand it if you've never worked with Paypal. The thing is I looked into the code trying to find a way to make it work, the closest I came to what I was searching for that that "worker.run job" approach but wasn't able to make it work, but any ideas are welcome since I still think it would be an elegant way to work with e-commerce.