title: Sidekiq error Uninitialized Constant
body: <p>I'm having an issue with sidekiq. Basically we're getting <code>NameError: uninitialized constant</code> on our sidekiq setup which is causing a large number of jobs to fail.</p>
  
  <p>The error log says:</p>
  
  <pre><code>NameError: uninitialized constant GameUser::Lock
  /data/@myapp/releases/20130321230952/app/models/game_user.rb:71:in `node_calls_base_get_user'
  /data/@myapp/shared/bundled_gems/ruby/1.9.1/gems/sidekiq-2.8.0/lib/sidekiq/processor.rb:45:in `block (3 levels) in process'
  /data/@myapp/shared/bundled_gems/ruby/1.9.1/gems/sidekiq-2.8.0/lib/sidekiq/middleware/chain.rb:109:in `call'
  </code></pre>
  
  <p>The code is here: </p>
  
  <pre><code># app/models/game_user.rb
  def self.node_calls_base_get_user(serial, game_name)
    if Lock.get("user:#{id}") # Set up lock to prevent multiple users to be created      
      Lock.delete("user:#{id}")
    end
    return false
  end
  </code></pre>
  
  <p>Lock is defined in a library: </p>
  
  <pre><code># lib/lock.rb
  class Lock
    def self.get(key)
      lock = CACHE.add("lock:#{key}", 1, 5) # Let lock autoexpire after 5 seconds
      return true
    end
  end
  </code></pre>
  
  <p>And the lib/ folder is automatically loaded with the rest of the configurations.</p>
  
  <pre><code>module Myapp
    class Application &lt; Rails::Application
      ...
      # Custom directories with classes and modules you want to be autoloadable.
      config.autoload_paths += %W(#{config.root}/lib)
      ...    
    end
  end
  </code></pre>
  
  <p>I have no idea why this is happening. It seems to happen more frequently when we deploy, but it seems to happen often enough otherwise.</p>
  
  <p>I've been following the following thread: <a href="https://github.com/mperham/sidekiq/issues/331" rel="nofollow">https://github.com/mperham/sidekiq/issues/331</a> but it doesn't seem to offer a solution besides adding the lib folder to the autoload_paths.</p>
  
  <p>I'm using: </p>
  
  <p>gem 'rails', '3.2.13'
  gem 'sidekiq', '>= 2.7.5'</p>
  
  <p>Any help would be greatly apreciated.</p>