-
Notifications
You must be signed in to change notification settings - Fork 4k
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 Webhook::DispatchEventJob to Sidekiq #5722
Move Webhook::DispatchEventJob to Sidekiq #5722
Conversation
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.
Looks good! I just restarted the build because it was failing in a weird way, I'll keep an eye on the result and approve later if all goes well
|
||
sidekiq_options queue: :medium_priority | ||
|
||
def perform(endpoint_url, event_json) |
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 thought I liked the old payload
better but not I'm unsure hahaha
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'm personally a fan of using a hash as arguments bc then it is clear what the params are without having to go into the job in the code to figure it out. But I'm good either way.
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 thought we had abandoned the idea in an old PR (not to use hash arguments) because they are not well supported by Sidekiq:
The arguments you pass to perform_async must be composed of simple JSON datatypes: string, integer, float, boolean, null(nil), array and hash. This means you must not use ruby symbols as arguments.
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 could go either way here.
I know we've discussed not using hash arguments and using hash arguments.
My thinking for doing it this way was based on a few thoughts:
- Since it's only 2 arguments, it's not quite as confusing as to what's being passed in.
- When the job is called, you can see what's being passed in since both arguments are built beforehand just above it:
def call
endpoint_urls = Endpoint.for_events([event_type]).where(user_id: record.user_id).pluck(:target_url)
return if endpoint_urls.empty?
event_json = Event.new(event_type: event_type, payload: PayloadAdapter.new(record).hash).to_json
endpoint_urls.each do |url|
DispatchEventWorker.perform_async(url, event_json)
end
end
- Since
event_json
is a Hash of its own, if we changed it to Hash arguments we'd have a nested Hash that we would probably want to dodeep_symbolize_keys!
on to keep everything consistent in the job. Not a big deal, but felt a little "dirtier" than necessary.
On the other hand, I'm all for the idea that using a Hash argument does improve clarity. I can just about always agree with that point!
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 we don't want to attempt to pass symbols, but a hash with string keys when you push past 3 arguments I think is a good idea. Like @atsmith813 mentioned, in this case we only have a couple, it's not a big deal, but the more you get a mapped hash is nice visibility I think. It makes it really easy to see in the dashboard what arguments are what.
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.
Probably should check out those spec failures, feels like we were possibly stubbing the old worker or something before.
|
||
sidekiq_options queue: :medium_priority | ||
|
||
def perform(endpoint_url, event_json) |
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'm personally a fan of using a hash as arguments bc then it is clear what the params are without having to go into the job in the code to figure it out. But I'm good either way.
What type of PR is this? (check all applicable)
Description
This creates a new
Webhook::DispatchEventWorker
(spec included) and starts sending jobs to it. Once this is merged and deployed, I will open a second PR to remove the old job code and spec.Related Tickets & Documents
Added to documentation?