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

Worker doesn't pickup jobs created by a mongoid embedded document #80

Open
jafuentest opened this issue Aug 13, 2019 · 1 comment
Open
Labels

Comments

@jafuentest
Copy link
Contributor

As the title says, you can't use the handle_asynchronously option inside an object that will be persisted as a subdocument.

In the example below, every time you create a comment, the job will be created, but when the worker picks it up for execution, nothing will happen because calling comment.find(:id) will return nil

class Post
  include Mongoid::Document
  embeds_many :comments
end

class Comment
  include Mongoid::Document
  embedded_in :post

  after_create :notify_post_author

  def notify_post_author
    Notification.create(user: post.user, text: 'you got a comment')
  end

  handle_asynchronously :notify_post_author, queue: 'notifications'
end

This is referenced in Issue #11 however it leads to another gem rather than a fix, so I'm curious as to why this wasn't addressed by this gem

@johnnyshields
Copy link
Collaborator

This is indeed an issue and I experienced this in my own app. The problem is that DelayedJob's class serialization is treating the embedded document as if it were a parent-level document, and looks for its collection.

Instead, we need to serialize the parent document, and then "drill-down" to the relevant embedded document -- potentially multiple levels of nesting.

I will consider a fix for this later.

@dblock dblock changed the title Worker doesn't pickup jobs created bya mongoid embedded document Worker doesn't pickup jobs created by a mongoid embedded document Jan 31, 2023
@dblock dblock added the bug? label Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants