In our Rails application. We save the model (video). We have a callback on this object:
after_create :send_to_background_job, :if => :persisted?
The method looks like this:
def send_to_background_job
Resque.enqueue(AddVideo, self.id)
end
When the worker is called. It performs the following actions:
class AddVideo
@queue = :high
def self.perform(video_id)
video = Video.find(video_id)
video.original_file_name
....
Resque-web reports an error:
AddVideo
Arguments
51061
Exception
NoMethodError
Error
undefined method `original_filename' for nil:NilClass
This is a little strange because if I go to the Rails console to watch this video. He exists. In addition, the Resque.enqueue(AddVideo, 51061)SECOND time call is executed without errors.
It looks like it takes longer to save a record in the database than it takes to create a work / job. But even this operator does not add up, since the object calls the Resque job only after the object is saved. In Rails, this is done using the callback method in the model ( after_create).
, . :
Resque.before_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Resque.after_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end