-
Notifications
You must be signed in to change notification settings - Fork 956
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
Job failed to load: undefined class/module User::Identity #779
Comments
The error says it can't find |
Yeah, I saw that, no idea where that is coming from. Will continue investigating, wasn't sure if that was more of a generic error. |
I'm having the same issue. For some reason delayed jobs isn't autoloading classes properly. Even manually requiring job classes via an initializer isn't fixing this issue for me. |
We don't do any loading or autoloading. That is all rails and usually means you have things defined in an unusual way |
I'm getting this when I have a job that uses a one of my own modules in the payload. |
I've been having this issue too, and it is seemingly random. Anyone come up with a solution? |
I got this error too, with the undefined class/module being the name of my Custom Job Struct. This issue comes up for me on my staging server, but not on local / development environment. The delayed job is being called within a rake task. FWIW: ssh'ing in and manually restarting the daemon (a la |
I'm also randomly getting a similar error (a different class fails to load for me). Sometimes my DJs work, and often they fail with this error. Has anyone come up with a solution? |
@DMcKinnon-mdsol, it turns out this whole time I was dealing with this issue, there were multiple instances of the daemon running (due to a faulty deploy script). There are some instructions here for seeing how many instances of delayed_jobs daemon are running and killing them. |
Oh, cool. This might actually be my problem, too. Thanks! |
I am getting this error, and the suggestion to include a custom initializer that loads the missing class did not work. Also, the suggestion of restarting the delayed_job worker did not work. I don't have multiple delayed_job workers running on the machine either. Has anyone else figured out another solution? It does not happen every time, only sometimes, but I cannot determine a pattern that makes sense. Here is an example of the failure message:
I tried creating a file called
But that did not seem to help. Here is my
And
And
And
I'm just confused as to why it works sometimes, and doesn't work other times. The missing file is located in Also, here is a sample of my delayed_job.log file from our production server:
The worker is clearly working sometimes, but no failures show up in the log. The failures only show up in the delayed_jobs table in the database. |
+1 I am getting this as well, seems to be random and I can't duplicate it if I login to the console and make the same call. |
We were encountering this error (Rails 5.0.2 and DelayedJob 4.1.2): We tried However, |
I'm not sure if it's helpful to anyone besides me, I use rake to start my delayed_job workers, and I just learned that rails overrides |
So I just ran into this issue and I can confirmed that after reading this the only think i needed to do was adding the |
I was having uninitialized class errors and the issue was due to my worker pools running off of an older release. See issue #911. |
In in my case I needed delay one method from |
I looked deeper into my stack trace and noticed that psych was doing some class loading. I then read this SO about it having issues resolving serialized classes: https://stackoverflow.com/questions/4705867/rails-doesnt-load-classes-on-deserializing-yaml-marshal-objects I added this monkey patch (for Rails4) and haven't had any problems since: module Psych::Visitors
ToRuby.class_eval do
alias :resolve_class_without_autoload :resolve_class
def resolve_class klassname
begin
require_dependency klassname.underscore
rescue NameError, LoadError
end
resolve_class_without_autoload klassname
end
end
end |
I think I'm also being affected by the same issue, here's the error message I'm getting:
As with the other above, it's intermittent and I can't see what's causing it. App is on Heroku, using DJ to send emails with a worker. Because it's an ActiveRecord class/module that isn't being found, would that still be an autoloading issue in Rails? Is the monkey patch above preventing the error from bubbling up from Psych? |
@maxshelley did you recently do a rails upgrade? That looks more like an ActiveRecord internal that may have moved between versions. |
@albus522 Yes, we have, but that errors seem to occurring for jobs that were, I think, created after the update. I don't feel like I've brought enough information to this conversation, I'm going to dig further, thank you for taking the time to respond and I think you're right about the Rails update being part of my issue. |
I made a pull request to help with this problem. # config/initializers/delayed_job.rb
# Monkey patch to use old class references
module Psych
class << self; attr_accessor :old_class_references end
@old_class_references = {}
class ClassLoader
private
def find klassname
klassname = ::Psych.old_class_references[klassname] || klassname
@cache[klassname] ||= resolve(klassname)
end
end
module Visitors
class ToRuby < Psych::Visitors::Visitor
def revive klass, node
if klass.is_a? String
klassname = ::Psych.old_class_references[klass] || klass
klass = Kernel.const_get(klassname) rescue klassname
end
s = register(node, klass.allocate)
init_with(s, revive_hash({}, node), node)
end
end
end
end
# Add all old dependencies (hash keys) pointing to new references (hash values)
Psych.old_class_references = {
'ActiveRecord::AttributeSet' => 'ActiveModel::AttributeSet'
# ...
} |
Just quickly contributing our situation here. In one of our views, we were trying to load the ActionView::Template::Error (undefined class/module Facility): For some reason, it could not load the The quick fix we used was literally calling the <% Facility -%>
<%= YAML.load( job.handler ).object.name %> Not sure what the root issue is but maybe that will help somebody in the meantime. Cheers. |
Thanks! This helps me to solve my issue! 👍 |
This is driving me batty, mostly due to the random nature of it.
We are running Rails 4.1 and I have a simple ActiveResource (not ActiveRecord) object called "User" with a method called "update_metadatas" (it takes a json hash as a param). So I'll load up a User object (let's call it u) and then call u.update_metadatas(data). Works great. However, when I do u.delay.update_metadatas(data), things go screwy.
Seemingly depending on the time or day or direction of the wind (ok not really), the above job will immediately fail with:
Job failed to load: undefined class/module User::Identity
The errors aren't that revealing.
Sometimes it will work great with no problems. This behavior happens on both development (local workstation) and production (Heroku).
My guess is that this is a preloading issue . . . i.e., it seems random only because it is affected by when the worker runs (before or after when the rest of the application loads). For example I'll have all the jobs fail for a 2 hour period, and then they'll start working again. I tried the suggestion about turning off config.threadsafe! in production.rb for rake tasks, but that doesn't work for Rails 4.1. I tried the suggestion of adding an initializer like "require 'user'", but that didn't help.
ANY ideas?
P.S. I also run Puma, not sure if that matters (I don't believe Puma is used for the rake tasks though).
The text was updated successfully, but these errors were encountered: