Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass newly created object to after_create callback in Rails

Everytime an object has been created i want to enqueue it in a Redis queue to check for certain properties. How can i add the created object directly as a parameter to the callback? So my redis job would do something like this:

class FurtherProcessCarJob
 #....

 def self.perform(order)
   puts order.id
 end 
end

whereas in the model

after_create Resque.enqueue FurtherProcessCar, #self

It is possible to hook a method to the callback and there look for the car again and the enqueue the object, but is it possible to do it directly?

like image 203
theDrifter Avatar asked Nov 06 '18 09:11

theDrifter


1 Answers

As I understand your question, something like this should work

class YourModel < ActiveRecord::Base
  #....
  after_create :enqueue_to_redis

  private 

  def enque_to_redis
     Resque.enqueue self, other_args
  end 
end
like image 68
VAD Avatar answered Nov 03 '22 01:11

VAD