librelist archives

« back to archive

LoadError - not finding ActiveRecord classes

LoadError - not finding ActiveRecord classes

From:
Rupert Fiasco
Date:
2011-06-20 @ 17:17
Using Ruby 1.9.2 and Resque 1.17.1.

I am trying to reference my ActiveRecord classes from a Resque job but
receiving a LoadError:

** [16:44:53 2011-06-20] 8577: got: (Job{activity} |
AlbumCreateActivity | [{"album_id"=>313}])
** [16:44:53 2011-06-20] 8577: resque-1.17.1: Forked 8663 at 1308588293
** [16:44:53 2011-06-20] 8663: resque-1.17.1: Processing activity
since 1308588293
** [16:44:54 2011-06-20] 8663: (Job{activity} | AlbumCreateActivity |
[{"album_id"=>313}]) failed: #<LoadError: Expected
/var/www/releases/20110620154942/app/models/db/album.rb to define
Album>

I start Resque via:

RAILS_ENV=production VVERBOSE=1 QUEUE=* rake environment resque:work

Event if I comment out a reference to Album in the jobs perform() - I
still get that error. In fact it doesnt matter what ActiveRecord model
I try to reference - I get either a LoadError or an Uninitialized
Constant exception.

The really weird thing is that 1 job works - and it does use AR
models. All other jobs fail. There is no rhyme or reason

Re: LoadError - not finding ActiveRecord classes

From:
Rupert Fiasco
Date:
2011-06-20 @ 18:43
I was able to solve this by adding the following line to my rake task
definition, so its now:

task resque:setup => :environment do
  ActiveRecord::Base.send(:descendants).each { |klass|  klass.columns }
end

This was critical as it forced Rails to load the classes at initialization.

I got the idea for this from Engine Yards blog post:
http://docs.engineyard.com/configure-and-deploy-resque.html



On Mon, Jun 20, 2011 at 10:17 AM, Rupert Fiasco <rufiasco@gmail.com> wrote:
> Using Ruby 1.9.2 and Resque 1.17.1.
>
> I am trying to reference my ActiveRecord classes from a Resque job but
> receiving a LoadError:
>
> ** [16:44:53 2011-06-20] 8577: got: (Job{activity} |
> AlbumCreateActivity | [{"album_id"=>313}])
> ** [16:44:53 2011-06-20] 8577: resque-1.17.1: Forked 8663 at 1308588293
> ** [16:44:53 2011-06-20] 8663: resque-1.17.1: Processing activity
> since 1308588293
> ** [16:44:54 2011-06-20] 8663: (Job{activity} | AlbumCreateActivity |
> [{"album_id"=>313}]) failed: #<LoadError: Expected
> /var/www/releases/20110620154942/app/models/db/album.rb to define
> Album>
>
> I start Resque via:
>
> RAILS_ENV=production VVERBOSE=1 QUEUE=* rake environment resque:work
>
> Event if I comment out a reference to Album in the jobs perform() - I
> still get that error. In fact it doesnt matter what ActiveRecord model
> I try to reference - I get either a LoadError or an Uninitialized
> Constant exception.
>
> The really weird thing is that 1 job works - and it does use AR
> models. All other jobs fail. There is no rhyme or reason
>