From 44fb5388b4a048c4fece7800bc9be04faa546949 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 17 Apr 2025 17:34:34 -0400 Subject: [PATCH] Made the all results page grouping better and fixed the advance wrestler job. --- app/jobs/advance_wrestler_job.rb | 7 ++++- app/views/layouts/application.html.erb | 1 + app/views/tournaments/all_results.html.erb | 2 +- app/views/tournaments/show.html.erb | 1 - .../kubernetes/manifests/mariadb-replica.yaml | 5 ++++ lib/tasks/finish_tournament_204.rake | 30 ++++++++++++------- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/jobs/advance_wrestler_job.rb b/app/jobs/advance_wrestler_job.rb index 3444686..d654ac8 100644 --- a/app/jobs/advance_wrestler_job.rb +++ b/app/jobs/advance_wrestler_job.rb @@ -9,6 +9,11 @@ class AdvanceWrestlerJob < ApplicationJob end def perform(wrestler, match) + # Add a small delay to increase chance of transaction commit + # without this some matches were getting a deserialization error when running the rake task + # to finish tournaments + sleep(0.5) + # Get tournament from wrestler tournament = wrestler.tournament @@ -18,7 +23,7 @@ class AdvanceWrestlerJob < ApplicationJob tournament: tournament, job_name: job_name, status: "Running", - details: "Match ID: #{match&.bout_number || 'No match'}" + details: "Match ID: #{match&.bout_number || 'No match'} Wrestler Name #{wrestler&.name || 'No Wrestler'}" ) begin diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 38ab575..b4719d7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -46,6 +46,7 @@

×<%= alert %>

<% end %>
<%# Horizontal scroll only %> +

<%= yield %>
diff --git a/app/views/tournaments/all_results.html.erb b/app/views/tournaments/all_results.html.erb index 8cfafb9..eacf192 100644 --- a/app/views/tournaments/all_results.html.erb +++ b/app/views/tournaments/all_results.html.erb @@ -1,4 +1,4 @@ -<% @matches.select{|m| m.finished == 1 && m.w1 && m.w2}.sort_by{|m| [ m.bout_number, m.bracket_position, m.weight.max ]}.each do |match| %> +<% @matches.select{|m| m.finished == 1 && m.w1 && m.w2}.sort_by{|m| [ m.round, -m.bracket_position, m.weight.max ]}.each do |match| %> <% if @round != match.round || @bracket_position != match.bracket_position %>

<%= match.bracket_position %> Round: <%= match.round %>

<% end %> diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index a37f462..6f5760d 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -1,4 +1,3 @@ -

<%= @tournament.name %> Info

diff --git a/deploy/kubernetes/manifests/mariadb-replica.yaml b/deploy/kubernetes/manifests/mariadb-replica.yaml index 602f1af..4ed8969 100644 --- a/deploy/kubernetes/manifests/mariadb-replica.yaml +++ b/deploy/kubernetes/manifests/mariadb-replica.yaml @@ -210,5 +210,10 @@ data: sync_binlog=1 # Flush binary logs after each transaction for safety read_only=0 # Default, will be managed by the init script expire_logs_days=7 # Retain binary logs for 7 days + + # if you want to ignore dbs to replicate + # replicate-ignore-db=wrestlingtourney-queue + # if you only want to replicate certain dbs + replicate-do-db=wrestlingtourney # /etc/mysql/mariadb.conf.d/70-mysettings.cnf diff --git a/lib/tasks/finish_tournament_204.rake b/lib/tasks/finish_tournament_204.rake index 923c8a0..22776d5 100644 --- a/lib/tasks/finish_tournament_204.rake +++ b/lib/tasks/finish_tournament_204.rake @@ -5,33 +5,46 @@ namespace :tournament do @tournament = Tournament.find(204) - Mat.create( + Mat.find_or_create_by( name: "1", tournament_id: @tournament.id ) - Mat.create( + Mat.find_or_create_by( name: "2", tournament_id: @tournament.id ) - Mat.create( + Mat.find_or_create_by( name: "3", tournament_id: @tournament.id ) - Mat.create( + Mat.find_or_create_by( name: "4", tournament_id: @tournament.id ) - Mat.create( + Mat.find_or_create_by( name: "5", tournament_id: @tournament.id ) GenerateTournamentMatches.new(@tournament).generate - sleep(180) + sleep(10) + while @tournament.reload.curently_generating_matches == 1 + puts "Waiting for tournament to finish generating matches..." + sleep(5) + end + @tournament.reload # Ensure matches association is fresh before iterating @tournament.matches.sort_by(&:bout_number).each do |match| match.reload if match.loser1_name != "BYE" and match.loser2_name != "BYE" + # Wait until both wrestlers are assigned + while match.w1.nil? || match.w2.nil? + puts "Waiting for wrestlers in match #{match.bout_number}..." + sleep(5) # Wait for 5 seconds before checking again + match.reload + end + puts "Finishing match with bout number #{match.bout_number}..." + # Choose a random winner wrestlers = [match.w1, match.w2] match.winner_id = wrestlers.sample @@ -63,10 +76,7 @@ namespace :tournament do # Mark match as finished match.finished = 1 - match.save - - # Pause to simulate processing delay - sleep(10) + match.save! end end end