Search code examples
ruby-on-railsdelayed-jobruby-on-rails-4.2

Upgrading to Rails 4.2 breaks Delayed::Job: Job failed to load: undefined method 'fetch_value'


Upgrading to Rails 4.2, everything working fine locally, push to production 'kaboom'. Every Delayed::Job failed with the same error.

Job failed to load: undefined method 'fetch_value' for #. Handler: " --- YAMLYAMLYAMLYAML "

The error message we're getting is coming from the function below, which is calling into different libraries, catching the actual error, and returning their own which makes it really difficult to debug.

  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

Other things that might be useful, we're only using Delayed::Job (not with Active::Job).

fetch_value is never called within delayed_job, it's an Active::Record method.


Solution

  • I came across a similar fetch_value error when I upgraded an app to Rails 4.2.1. To get a closer understanding of the error, grab any job with this error and run the following in the rails console:

    YAML.load_dj(Delayed::Job.find(JOB_ID).handler)

    It runs internal delayed job code, but should give you a better trace for debugging.

    source: https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/backend/base.rb#L90

    The error is likely the result of queueing/creating jobs pre-Rails 4.2 upgrade and before setting config.active_job.queue_adapter = :delayed_job in your application.rb. If the config was not properly set, then jobs would be serialized in a format that Rails 4.2 cannot handle. To run any jobs with the fetch_value error, you can switch to a branch of your code still on > Rails 4.2 and run the jobs from the rails console.