I have a class in my /lib folder that my delayed_job daemon calls to work on an object of type Foo. If I don't have a "requires 'foo'" in the worker class then it doesn't know what to do with the YAML it gets from the DB and I get the "undefined method" error. Adding in "requires 'foo'" will obviously fix this, which is the usual solution.
But..the problem is that I have counter_cache=>true in class Foo. So what happens is that when the DJ daemon loads the Rails environment, Foo gets auto-loaded and a callback is added for my counter_cache. Then the delayed_job daemon runs, performs the "requires 'foo'" and it obediently reloads Foo and adds yet another callback for the counter_cache, which results in my counter_cache getting updated twice for every row added or deleted.
Is there a way to wrap :counter_cache=>true so it only runs once? Is there a way to get my DJ worker class to use an object of type 'Foo' without having to explicitly use 'requires'?