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 Webhook::DispatchEventJob to Sidekiq #5722

Conversation

atsmith813
Copy link
Contributor

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

  • Refactor
  • Optimization

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?

  • no documentation needed

moving_gif

@atsmith813 atsmith813 requested a review from a team January 25, 2020 00:03
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Jan 25, 2020
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.

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)
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

@rhymes rhymes Jan 27, 2020

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.

from https://github.com/mperham/sidekiq/wiki/Best-Practices

Copy link
Contributor Author

@atsmith813 atsmith813 Jan 27, 2020

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:

  1. Since it's only 2 arguments, it's not quite as confusing as to what's being passed in.
  2. 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
  1. 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 do deep_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!

Copy link
Contributor

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.

Copy link
Contributor

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

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.

@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 Jan 27, 2020
@mstruve mstruve merged commit 591ac77 into forem:master Jan 27, 2020
@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 Jan 27, 2020
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.

None yet

3 participants