Occam versus House

When I’m troubleshooting a problem, the first tool I reach for is Occam’s Razor. 99% of the time, I find a simple solution to a problem, possibly write a unit test (assuming we’re not talking about a bad ground in my stupid old car), and move on.

Some days, though, I endure my own personal episode of House.

So it was, after trying to track down a particularly unsettling problem where my model observer — which tested out just fine over and over again — simply failed to fire in a staging environment AFTER it worked a few times first. After slashing at the problem with Occam’s Razor to the point where there was nothing left but very tiny bits of flesh (ew), I put on House’s cap (or cane, as it were).

What if the code was, literally, disappearing?

Well, it turned out that was exactly what was happening. For other reasons that remain unresolved, I was instantiating my observer class using ObserverClass.instance as opposed to adding the class to the config.active_record.observers in environment.rb. This, coupled with the unfortunate configuration mistake that kept the site running in “development” mode, and this reloading-all-of-Creation before every new request caused the observer simply to fall off into oblivion as if it had never existed.

And why did it work a couple of times before failing? nginx –> 3 mongrel servers. Succeeded once for each server before the observer went completely bye-bye.

Although the true solution lies in reworking my application-environment-specific configuration, the short term solution was simply to add the observer to the config.active_record.observers after I had instantiated it.

Leave a Reply