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

WCA Live Integration Pre Work #1: Job and Websockets #10684

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
25 changes: 25 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
# For Live we don't care about only letting authenticated users connect
# We might want to change this for other use cases

# identified_by :current_user
#
def connect
reject_unauthorized_connection if EnvConfig.WCA_LIVE_SITE?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line with my other comment: reject unless WcaLive.enabled?

end
#
# private
#
# def find_verified_user
# user_id = cookies.encrypted["_WcaOnRails_session"]["warden.user.user.key"][0]
# if (verified_user = User.find_by(id: user_id))
# verified_user
# else
# reject_unauthorized_connection
# end
# end
end
end
7 changes: 7 additions & 0 deletions app/channels/live_results_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class LiveResultsChannel < ApplicationCable::Channel
def subscribed
stream_from "results_#{params[:round_id]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared constant yay

end
end
11 changes: 11 additions & 0 deletions app/jobs/add_live_result_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class AddLiveResultJob < ApplicationJob
self.queue_adapter = :shoryuken if Rails.env.production? && !EnvConfig.WCA_LIVE_SITE?
queue_as EnvConfig.LIVE_QUEUE if Rails.env.production? && !EnvConfig.WCA_LIVE_SITE?
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the if check into a globally accessible WcaLive.enabled? variable like we did with paypal?


def perform(params)
ActionCable.server.broadcast("results_#{params[:round_id]}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please share this broadcast key (perhaps in the same module as the "WCA Live enabled?" feature above)

{ attempts: params[:results], user_id: params[:user_id] })
end
end
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<meta name="og:image" content='<%= asset_url("og-wca_logo.png") %>'/>

<%= action_cable_meta_tag %>

<meta name="description" content="The World Cube Association governs competitions for mechanical puzzles that are operated by twisting groups of pieces, commonly known as 'twisty puzzles'. The most famous of these puzzles is the Rubik's Cube, invented by professor Rubik from Hungary. A selection of these puzzles are chosen as official events of the WCA.">

<title><%= full_title(yield(:title)) %></title>
Expand Down
2 changes: 2 additions & 0 deletions env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
mandatory :ASSET_HOST, :string
mandatory :CDN_ASSETS_DISTRIBUTION_ID, :string
mandatory :REGISTRATION_QUEUE, :string
mandatory :LIVE_QUEUE, :string

if is_compiling_assets
mandatory :V2_REGISTRATIONS_POLL_URL, :string
Expand All @@ -59,6 +60,7 @@
optional :PAYPAL_BASE_URL, :string, ''
optional :WRC_WEBHOOK_URL, :string, ''
optional :REGISTRATION_QUEUE, :string, ''
optional :LIVE_QUEUE, :string, ''

optional :V2_REGISTRATIONS_POLL_URL, :string, ''
optional :V3_REGISTRATIONS_POLL_URL, :string, ''
Expand Down
4 changes: 4 additions & 0 deletions infra/wca_on_rails/production/rails.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ locals {
name = "REGISTRATION_QUEUE"
value = aws_sqs_queue.this.url
},
{
name = "LIVE_QUEUE"
value = aws_sqs_queue.results.url
},
{
name = "VAULT_APPLICATION"
value = var.VAULT_APPLICATION
Expand Down
14 changes: 14 additions & 0 deletions infra/wca_on_rails/production/sqs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ resource "aws_sqs_queue" "this" {
Env = "Production"
}
}

resource "aws_sqs_queue" "results" {
name = "results-monolith"
content_based_deduplication = true
deduplication_scope = "queue"
delay_seconds = 0
max_message_size = 262144
message_retention_seconds = 345600
receive_wait_time_seconds = 0
visibility_timeout_seconds = 60
tags = {
Env = "Production"
}
}
4 changes: 4 additions & 0 deletions infra/wca_on_rails/staging/rails.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ locals {
name = "REGISTRATION_QUEUE"
value = aws_sqs_queue.this.url
},
{
name = "LIVE_QUEUE"
value = aws_sqs_queue.results.url
},
{
name = "STORAGE_AWS_REGION"
value = var.region
Expand Down
14 changes: 14 additions & 0 deletions infra/wca_on_rails/staging/sqs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ resource "aws_sqs_queue" "this" {
Env = "staging"
}
}

resource "aws_sqs_queue" "results" {
name = "results-staging-monolith"
content_based_deduplication = true
deduplication_scope = "queue"
delay_seconds = 0
max_message_size = 262144
message_retention_seconds = 345600
receive_wait_time_seconds = 0
visibility_timeout_seconds = 60
tags = {
Env = "Staging"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@fullcalendar/luxon3": "^6.1.15",
"@fullcalendar/react": "^6.1.15",
"@fullcalendar/timegrid": "^6.1.15",
"@rails/actioncable": "^8.0.100",
"@rails/ujs": "^7.1.501",
"@stripe/react-stripe-js": "^3.1.1",
"@stripe/stripe-js": "^5.5.0",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,13 @@ __metadata:
languageName: node
linkType: hard

"@rails/actioncable@npm:^8.0.100":
version: 8.0.100
resolution: "@rails/actioncable@npm:8.0.100"
checksum: 10c0/ae8870083e5c48448bd1d77268d28a16d7eee6d213dac8a6e20888c47d89ac959c4e835a613beaaa71b13b9aaaea14c4fb6d67120f972d174f1f899dd5a37e45
languageName: node
linkType: hard

"@rails/ujs@npm:^7.1.501":
version: 7.1.501
resolution: "@rails/ujs@npm:7.1.501"
Expand Down Expand Up @@ -10225,6 +10232,7 @@ __metadata:
"@fullcalendar/react": "npm:^6.1.15"
"@fullcalendar/timegrid": "npm:^6.1.15"
"@pmmmwh/react-refresh-webpack-plugin": "npm:^0.5.15"
"@rails/actioncable": "npm:^8.0.100"
"@rails/ujs": "npm:^7.1.501"
"@stripe/react-stripe-js": "npm:^3.1.1"
"@stripe/stripe-js": "npm:^5.5.0"
Expand Down
Loading