tieoea
Last Updated: February 25, 2016
·
1.062K
· demiazz

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.

1 Response
Add your response

7784

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

over 1 year ago ·