title: Delayed job: How to reload the payload classes during every call in Development mode
body: <p>I am running a delayed job worker. When ever I invoke the <code>foo</code> method, worker prints <code>hello</code>. </p>
  
  <pre><code>class User
    def foo
      puts "Hello"
    end
    handle_asynchronously :foo
  end
  </code></pre>
  
  <p>If I make some changes to the <code>foo</code> method, I have to restart the worker for the changes to reflect. In the development mode this can become quite tiresome. </p>
  
  <p>I am trying to find a way to reload the payload class(in this case User class) for every request. I tried monkey patching the DelayedJob library to invoke <code>require_dependency</code> before the payload method invocation.</p>
  
  <pre><code>module Delayed::Backend::Base
    def payload_object_with_reload
      if Rails.env.development? and @payload_object_with_reload.nil?
        require_dependency(File.join(Rails.root, "app", "models", "user.rb"))
      end
      @payload_object_with_reload ||= payload_object_without_reload
    end
    alias_method_chain :payload_object, :reload
  end
  </code></pre>
  
  <p>This approach doesn't work as the classes registered using <code>require_dependency</code> needs to be reloaded before the invocation and I haven't figured out how to do it. I spent some time reading the dispatcher code to figure out how Rails reloads the classes for every request. I wasn't able to locate the reload code. </p>
  
  <p>Has anybody tried this before? How would you advise me to proceed? Or do you have any pointers for locating the Rails class reload code?</p>