Trying to get delayed_job working with a mongoid backend. The created job fails to run, apparently because it is being pushed to the db.entries collection, rather than the db.delayed_backend_mongoid_jobs collection.
Given the following code in the class Entry:
after_create :create_dj
def create_dj
Rails.logger.info "ENTRY CREATED at #{created_at}"
end
handle_asynchronously :create_dj, run_at: Proc.new { 30.seconds.from_now }
I would expect a new delayed_job entry would be created in the delayed_backend_mongoid_jobs collection. Instead, I see the following db log:
MONGODB health_blog_development['entries'].insert([
{"content"=>"foo", "_id"=>BSON::ObjectId('4ee95ed3b643988551000044') ... },
{"priority"=>0, "attempts"=>0, "handler"=>"--- !ruby/struct:Delayed::PerformableMethod ... }])
as if it thinks it should be pushing the job to the entries collection.
Some details that might be relevant:
- Entry has been subclassed. I’ve tried the code in Entry and its subclass, TextEntry.
- The function runs find when handle_asynchronously is not being used.
- Entry is not an embedded class, but does have several referenced relations.
- I’ve set config.mongoid.preload_models = true
- I have confirmed that delayed_job works as expected when I use it with a new model in the same project.
Gems used:
- mongoid (2.2.4)
- rails (3.0.9)
- delayed_job (2.1.4)
- delayed_job_mongoid (1.0.4)
Please let me know if there’s any other details that might help figure out what’s going on here. Cheers!
This appears to be funny behaviour resulting from the combination of delayed_job and the Apotomo widget framework. Changing the process to use regular Rails forms rather than the Apotomo url_for_event process solves the issue.