Using delayed_job on a non-ActiveRecord class

I'm attempting to use handle_asynchronously on a method of a class, as per the following:

class MyClass
  def publish_stream(opts={})
    # . . .
  handle_asynchronously :publish_stream

When delayed_job attempts to execute, it throws the following exception:

NoMethodError: undefined method `publish_stream_without_send_later' for #<YAML::Object:0xbb52b00>

(Note that the I replaced the actual method name with "my_method" above.)

I believe the exception is occurring because the class defining this method is not derived from ActiveRecord::Base; instead, it's simply derived from Object. What can I do to resolve this?


My guess is that DelayedJob tries to serialize the object you are working on, and it cannot recreate the object from that.

After some digging, it turns out that the delayed_job rake task must be loading something in the wrong order. It worked fine in the console. The solution was to do the following manually in an initializer:

require 'my_class'

where "my_class" is the filename of the class.


 ? PHP error: Notice: Undefined index:
 ? undefined amount of data in multidimensional array in PHP
 ? Why do it get parent.childElementCount as undefined
 ? Rails.env undefined in Rails 2
 ? Problem with jQuery openDatabase(): variable db is undefined
 ? Javascript function undefined
 ? `$ is not defined` for jQuery
 ? getResources does not work / undefined Java
 ? typeof usage for undefined variables
 ? typeof usage for undefined variables