tieoea
Last Updated: February 25, 2016
·
997
· demiazz
71e9761dce27485eb3ced22ed60f59d1

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.

Say Thanks
Respond

1 Response
Add your response

7784
5d9ab3ae2edd0527f0b50c6bd1c7b4b3

This is awesome, thanks for the tip. Can you explain why delayed_job would have trouble serializing an observer instance?

over 1 year ago ·