-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Change MentionJob to MentionWorker and move to sidekiq #5312
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
Conversation
@@ -0,0 +1,11 @@ | |||
module Notifications |
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.
I created a notifications module to mimick the notifications module in the job directory
class MentionWorker | ||
include Sidekiq::Worker | ||
sidekiq_options queue: :high_priority, retry: 10 | ||
|
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.
Not super sure about the queue here🙈 I presume sending Mentions to users should not be delayed heavily, but happy to change this :)
|
||
def perform(mention_id) | ||
mention = Mention.find_by(id: mention_id) | ||
Notifications::NewMention::Send.call(mention) if mention |
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.
This used to be passed in the old job code as an object. I am using it here directly, let me know you would like a further refactor
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.
I think it's fine in this instance, because what you call is a class method, so there's no risk of mocking the wrong instance!
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.
@rhymes separate from this PR, we have lots of jobs that do send if object
which means when we dont have one we silently fail. What do you think about that? Do you think we should change that pattern to raise an error possibly?
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.
I think @lightalloy has a better point of view on this but in general IIRC the gist is that we don't need to be alerted for resources that are not present in the DB 99% of the time. The other 1% we need to figure out case by case.
I think we shouldn't take this decision while we're doing this "moving" sprint. Let's move over the jobs to Sidekiq and then we can go through the jobs and decide which ones are worth bubbling the errors for.
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.
@rhymes is right about the motivation of adding the check. The job doesn't actually fail as it used to do before adding this checks, but gets canceled.
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.
This is a great PR @serenaf!
I think you're almost to the finish line, I left a note about the tests :)
|
||
def perform(mention_id) | ||
mention = Mention.find_by(id: mention_id) | ||
Notifications::NewMention::Send.call(mention) if mention |
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.
I think it's fine in this instance, because what you call is a class method, so there's no risk of mocking the wrong instance!
end | ||
|
||
it "calls a service" do | ||
perform_enqueued_jobs do |
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.
this is related to ActiveJob
and can be removed
end | ||
|
||
it "does nothing for non-existent mention " do | ||
perform_enqueued_jobs do |
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.
this is related to ActiveJob
and can be removed
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.
Thank you @serenaf for the PR!!! This looks great! Let's change that queue and delete some of those leftover ActiveJob specs and we will be ready to go!
|
||
def perform(mention_id) | ||
mention = Mention.find_by(id: mention_id) | ||
Notifications::NewMention::Send.call(mention) if mention |
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.
@rhymes separate from this PR, we have lots of jobs that do send if object
which means when we dont have one we silently fail. What do you think about that? Do you think we should change that pattern to raise an error possibly?
perform_enqueued_jobs do | ||
Mention.create_all(comment) | ||
Notification.send_mention_notification(Mention.first) | ||
Sidekiq::Testing.inline! do |
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.
Ideally, I want to make a nice little testing helper for this but thank you for doing it here by hand!!!
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.
LGTM 🚀
What type of PR is this? (check all applicable)
Description
I followed the PR here:
This creates a new MentionWorker and starts sending jobs to it from the Notification model. Once this is deployed, I will open a second PR to remove the old code.
Starting small, if this looks good, i can tackle more of the Notification jobs :)
Related Tickets & Documents
#5305
Added to documentation?