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

Move user.follow delay calls to ActiveJob (#3136) #4203

Merged
merged 2 commits into from
Oct 3, 2019

Conversation

johncurcio
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Refactor

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?

  • no documentation needed

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 3, 2019
@johncurcio
Copy link
Contributor Author

In app/jobs/users/follow_job.rb:5, I was conflicted between passing user_id, followable_id and followable_type to the active job (which seems to be what's most used in the codebase) and passing the objects user and followable directly. I opted for the latter, because it made things simpler/cleaner, but let me know if you think the former is more appropriate.

@rhymes
Copy link
Contributor

rhymes commented Oct 3, 2019

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

Copy link
Contributor

@rhymes rhymes left a 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

@pr-triage pr-triage bot added PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 3, 2019
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes labels Oct 3, 2019
@rhymes rhymes requested a review from lightalloy October 3, 2019 13:18
Copy link
Contributor

@lightalloy lightalloy left a 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)
Copy link
Contributor

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.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 3, 2019
@benhalpern benhalpern merged commit 432d334 into forem:master Oct 3, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants