-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Move user.follow delay calls to ActiveJob (#3136) #4203
Conversation
In |
Hi @johncurcio, thanks a lot, unfortunately in this case the former is the way to go, for serialization and concurrency issues. Between the queueing of the object and the moment the job is executed the resource could have disappeared from the database, which would mean that the job would fail indefinitely. We also don't want to serialize the object themselves The pattern is: pass IDs, load the objects from the DB inside the job, exit the job if the objects don't exist and then perform the actual operation. You can see a couple of good examples in the source code: https://github.com/thepracticaldev/dev.to/blob/master/app/jobs/articles/score_calc_job.rb and this is a good example of how to load an object by type and id https://github.com/thepracticaldev/dev.to/blob/master/app/jobs/notifications/notifiable_action_job.rb I'm going to formally request changes, so that other reviewers will see the label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment here, the basic structure of the code is there, it just needs to be updated to follow a safer pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, thanks for the contribution!
it "doesn't follow user" do | ||
expect do | ||
described_class.perform_now(user.id, invalid_id, followable.class.name) | ||
end.to change(Follow, :count).by(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, you can use not_to change(Follow, :count)
instead of checking that it was changed by 0.
What type of PR is this? (check all applicable)
Description
Move
user.follow
delay calls to ActiveJob.Related Tickets & Documents
#3136
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
No UI changes.
Added to documentation?