4543

DelayedJob: How to solve the problem “Job failed to load”?

I am using Ruby on Rails 3.1.0 and DelayedJob. As many people on the web I get the "Job failed to load: uninitialized constant Syck::Syck" error, but I think I discovered at least what generates the error (in my case). I have an ActiveModel like the following:

class Contact include ActiveModel::Conversion include ActiveModel::Validations include ActiveModel::Dirty extend ActiveModel::Naming extend ActiveModel::Translation attr_accessor :full_name, :email, :subject, :message def initialize(attributes = {}) attributes.keys.each do |attr| instance_variable_set "@" + attr.to_s, attributes[attr.to_sym] end end validates_presence_of :full_name, :email, :subject, :message def persist @persisted = true end def persisted? false end end

The related controller action is:

def contact @contact = Contact.new(params[:contact]) if @contact.valid? ::Contact::Mailer.delay.contact(@contact) respond_to do |format| format.html { redirect_to root_path } end else respond_to do |format| format.html { render :action => :contact } end end end

I noted that my problem with the "famous"\"infamous" Job failed to load: uninitialized constant Syck::Syck happens only if I run the @contact.valid?. If I re-implement the above controller action like this:

def contact @contact = Contact.new(params[:contact]) ::Contact::Mailer.delay.contact(@contact) respond_to do |format| format.html { redirect_to root_path } end end

all work as expected: I don't get the error and the e-mail is successfully sent. In few words, when I run @contact.valid? inside the controller action (I can run that also without using the if ... else statement) it generates the Job failed to load error. I really do not understand this strange behavior related to the DelayedJob gem and the valid? method.

<strong>Why it happens? How can I solve the problem?</strong>

<hr>

More info at DelayedJob: “Job failed to load: uninitialized constant Syck::Syck”

<hr>

<strong>UPDATES</strong>

If I debug the @contact.errors in both <strong>cases</strong> using or not using the @contact.valid? method...

<strong>... when</strong> I use the @contact.valid? method (DelayedJob does not work) I get

#<ActiveModel::Errors:0x00000101759408 @base=#<Contact:0x000001017597f0 @full_name="Sample name", @email="foo@bar.com", @subject="Sample subject", @message="Sample message content.", @validation_context=nil, @errors=#<ActiveModel::Errors:0x00000101759408 ...>>, @messages={}>

<strong>... when</strong> I do not use the @contact.valid? method (DelayedJob works) I get

#<ActiveModel::Errors:0x00000101759408 @base=#<Contact:0x000001017597f0 @full_name="Sample name", @email="foo@bar.com", @subject="Sample subject", @message="Sample message content.", @errors=#<ActiveModel::Errors:0x00000101759408 ...>>, @messages={}>

Note that in the second case the @validation_context=nil is not present and that in both cases there is a "nested" <ActiveModel::Errors:0x0000010175940 ...> statement. <strong>Is that a bug?</strong>

Answer1:

I found a solution that works for me. You can redefine the 'Object#to_yaml_properties' method within your Contact class to only include the properties you need. And thus exclude the 'errors' variable.

def to_yaml_properties ['@full_name', '@email', '@subject', '@message'] end

Hope this helps.

Recommend

  • how to initialise a rails gem which add associations to models specified by user
  • Cannot create firefox browser with watir-webdriver
  • Devise authentication undefined method 'to_sym'?
  • Overriden method still gets called
  • OpenJPA 1.2.x select tree structure using JPQL
  • DelayedJob: How to solve the problem “Job failed to load”?
  • Android emulator sd card image already in use
  • Cascade persist creates duplicate rows?
  • SqlBulkCopy.WriteToServer() keep getting “connection is closed”
  • Google App Engine - Memcache - How likely am I to lose data in this scenario?
  • Do android scheduled jobs survive an app upgrade?
  • How to override FOSUserBundle/Doctrine/UserManager.php
  • war file generated by Grails ignores dataSource URL
  • Persist Sockets over page refresh and page changes
  • How does Spark evict cached partitions?
  • How to copy an image from PhotoChooserTask to a Bitmap
  • WSO2 analytics datasource
  • Automatic update of parent record updated_at field (Elixir-Ecto)
  • Since when does sqlite's persist journal mode become the default journal mode in Android?
  • JAVA EE Stateless EJB IllegalArgumentException: Can not set field
  • Seahorse::Client::NetworkingError Amazon S3 file upload with rails
  • How to add and access Custom Header in C#
  • Incomplete PHP class when serializing object in sessions
  • FactoryGirl factory with Trait(s) that returns a Hash with stringed keys
  • 1 to 1..0 relationship in an embedded form with doctrine
  • Can I Modify Hibernate/JPA Attribute Dynamically?
  • declare a transaction in ejb 3.0
  • FullTextHibernateSessionProxy is not visible from class loader
  • Ruby on Rails Active Record RANDOM() always the same within a loop
  • applying background to first, and every third row in a dynamically generated table
  • rails 5 carrierwave no route matches for image
  • yii2 create translated URLs
  • Can I use jquery to blank textarea fields or ajax like input boxes?
  • JPA CascadeType.REMOVE not working
  • changes in jquery 1.4.2 breaking the code?
  • jquery code not working without breakpoint
  • SAVE attribute needed for Fortran variables when only the C_LOC address is returned to a C program?
  • saving file generated by TCPDF
  • d3 v4 drag and drop with TypeScript
  • Can't mass-assign protected attributes when import data from csv file