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

Job failed to load: undefined method `load_dj' for Syck:Module. #786

Closed
manjunath-nm89 opened this issue Feb 25, 2015 · 10 comments · May be fixed by #855
Closed

Job failed to load: undefined method `load_dj' for Syck:Module. #786

manjunath-nm89 opened this issue Feb 25, 2015 · 10 comments · May be fixed by #855

Comments

@manjunath-nm89
Copy link

Submitted a job and ran a DJ worker and the job failed with an exception Job failed to load: undefined method 'load_dj' for Syck:Module.

This is my configuration
  • delayed_job version - 4.0.6
  • delayed_job_active_record - 4.0.3
  • Rails - 3.1.12
  • YAML ENGINE: YAML::ENGINE.yamler= 'syck'
Exception Trace

Job failed to load: undefined method `load_dj' for Syck:Module.
Handler: "--- !ruby/object:Delayed::PerformableMethod \nargs: \n- 198\n- 2015-02-25 01:08:41.226804 Z\nmethod_name: :set_favorite_last_accessed\nobject: !ruby/class SegmentReportQueriesController\n"

@albus522
Copy link
Member

You have to set the YAML engine before DJ is required or the correct files will not be loaded. This means you have to set the YAML engine at the top of your config/environment.rb file before the Bundler.require line.

Also be aware many libraries are dropping Syck support and we probably will as well.

@manjunath-nm89
Copy link
Author

I had the YAML ENGINE configuration in my boot.rb and tried with environment.rb as well. Both of them did not work. Digging into the gem now.

@manjunath-nm89
Copy link
Author

I also checked that before the delayed job library is loaded, the YAML engine is correctly set to Syck

@manjunath-nm89
Copy link
Author

The below code is from delayed/backend/base.rb For some reason the def load_dj defined in syck_ext.rb is not getting included.

def payload_object
  @payload_object ||= YAML.load_dj(handler)
  rescue TypeError, LoadError, NameError, ArgumentError, SyntaxError, Psych::SyntaxError => e
  raise DeserializationError, "Job failed to load: #{e.message}. Handler: #{handler.inspect}"
end

@albus522
Copy link
Member

What version of ruby?

@manjunath-nm89
Copy link
Author

ruby 1.9.3p484

@albus522 albus522 reopened this Feb 27, 2015
@albus522
Copy link
Member

So Syck detection does not work in 1.9.3. I can't test if 1.9.2 worked, and 2.0 removed Syck support. Given that 1.9.3 is now EOL and you are the only person with this issue in 3 years, our fix is probably going to be to remove the Syck extensions entirely, which doesn't help you, but If you fork and change https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/yaml_ext.rb#L5 to

if /syck|yecht/i.match(YAML.parser.class.name)

it should load the correct libraries but it still may not work.

@manjunath-nm89
Copy link
Author

Yeah, I had already tried your fork and code change and it did not work. I have monkey patched a fix for now. We will be moving to Ruby 2.x shortly.

Thanks for your prompt responses.

@CarlosCD
Copy link

Hey Manjunath,

I am not sure if this is the fix you implemented, but this works well for me (added in a Rails initializer):

module Delayed
  module Backend
    module Base
      def payload_object
        if YAML.respond_to? :load_dj
          @payload_object ||= YAML.load_dj(handler)
        elsif YAML.respond_to? :unsafe_load
          @payload_object ||= YAML.load(handler, safe: false)
        else
          @payload_object ||= YAML.load(handler)
        end
      rescue TypeError, LoadError, NameError, ArgumentError, SyntaxError, Psych::SyntaxError => e
        raise DeserializationError, "Job failed to load: #{e.message}. Handler: #{handler.inspect}"
      end
    end
  end
end

I am using:

  • Ruby 1.9.3-p484 (hopefully migrating soon to 2.2.2, if I can get my way)
  • Rails 4.2.3
  • delayed_job_active_record 4.0.3 (monkey patched for PostgreSQL 9.0)
  • delayed_job 4.0.6

@manjunath-nm89
Copy link
Author

Carlos,

This is kind of the same fix which I monkey-patched and it works well for me. We have moved to Ruby 2.1 though and the monkey-patch is no longer needed.

tanelj added a commit to tanelj/delayed_job that referenced this issue Oct 12, 2015
Fixes "Job failed to load: undefined method `load_dj' for Syck:Module" when
Syck is used as YAML engine

Fixes collectiveidea#786
dawidpawliszko added a commit to zendesk/delayed_job that referenced this issue Feb 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants