Rails observers and DelayedJob
When you need use observers with DJ, don't call observer instance methods as asynchronously. You need do like this:
class UserObserver
  def after_save(user)
    self.class.do_something_with user
  end
  protected
  class << self
    def do_something_with user
      some_hard_action_on_user user
    end
    handle_asynchronously :do_something_with
  end
end
DJ would probably have an interesting time serializing and deserializing an observer instance, especially considering observers are singleton classes.
Written by Alexey Plutalov
Related protips
1 Response
This is awesome, thanks for the tip. Can you explain why delayed_job would have trouble serializing an observer instance?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Rails 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#