Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker can't load model instances #65

Closed
TeuF opened this issue May 11, 2010 · 9 comments
Closed

Worker can't load model instances #65

TeuF opened this issue May 11, 2010 · 9 comments
Labels

Comments

@TeuF
Copy link

TeuF commented May 11, 2010

script/delayed_job run and rake jobs:work will fail if there are jobs that use instances of models and the models are not explicitly required.

$ ./script/delayed_job run      
Job failed to load: invalid subclass. Try to manually require the required file.

This is caused by the new serialization code, which relies on YAML for serializing and deserializing models.

@bkeepers
Copy link

This is actually an issue with the new yaml serialization/deserialization code. I've updated the issue to reflect the actual problem.

As a short term workaround, require your models in an initializer.

@paulsturgess
Copy link

+1 for a fix on this. I feel dirty listing my models in an intiializer.

@bkeepers
Copy link

I'm working on it. The internals of yaml are nasty. But I just need to find where it tries to load the constant and make it use ActiveSupport's class loading

@wikyd
Copy link

wikyd commented May 19, 2010

When I require my models in an initializer, I run into another issue when running in development mode where the model can only be loaded for one request before throwing an exception (caused by the activesupport class reloading, I think). Any ideas on how to get around this issue as well?

@bkeepers
Copy link

constantize objects when deserializing so that ActiveSupport can attempt its auto loading magic

Closed by 4c53af8

@stevenharman
Copy link

I presume this has the same root cause as silently removing jobs who's handlers can't be loaded? https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-jobs_are_silently_removed_from_the_database

This is back in DJ 3. Any plans to fix it?

@bryckbost
Copy link

@stevenharman Is this an issue you're experiencing with 3.0.2? We've tried to keep the serialization the same.

@stevenharman
Copy link

@bryckbost Yes. Well, actually, its not with an AR Model, but a custom job. In particular, I have MyCustomJob in app/models/my_custom_job.rb, which looks like

class MyCustomJob < Struct.new(:foo, :bar)
    def perform
      #do interesting stuff here.
    end
end

Which is enqueued thusly

Delayed::Job.enqueue MyCustomJob.new('this', 42)

When trying to unmarshal the handler, it fails and silently removes the job. This took way too long to track down, but explicitly requiring the custom class has "fixed" it.

# config/initializers/delayed_job.rb
require 'my_custom_job'

All of this started upon upgrading from 2.x to 3.0.

@apolzon
Copy link

apolzon commented Aug 2, 2012

I have run into this on latest 3.x, after changing my yaml engine to syck from psych.

Explicitly requiring classes in an initializer fixes it, but is not a solution I am happy about.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants