1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Added job_owner and 'description' to delayed_job to show on the tournament show page

This commit is contained in:
2019-11-26 23:40:01 -05:00
parent 2f4ea5e42f
commit 661c56d04e
7 changed files with 91 additions and 39 deletions

View File

@@ -31,12 +31,18 @@ class School < ActiveRecord::Base
end end
def calculate_score def calculate_score
newScore = total_points_scored_by_wrestlers - total_points_deducted if Rails.env.production?
self.delay(:job_owner_id => self.tournament.id, :job_owner_type => "Calculate team score for #{self.name}").calculate_score_raw
else
calculate_score_raw
end
end
def calculate_score_raw
newScore = total_points_scored_by_wrestlers - total_points_deducted
self.score = newScore self.score = newScore
self.save self.save
end
if Rails.env.production?
handle_asynchronously :calculate_score
end end
def total_points_scored_by_wrestlers def total_points_scored_by_wrestlers

View File

@@ -12,6 +12,10 @@ class Tournament < ActiveRecord::Base
attr_accessor :import_text attr_accessor :import_text
def deferred_jobs
Delayed::Job.where(job_owner_id: self.id)
end
def self.search(search) def self.search(search)
where("date LIKE ? or name LIKE ?", "%#{search}%", "%#{search}%") where("date LIKE ? or name LIKE ?", "%#{search}%", "%#{search}%")
end end

View File

@@ -5,17 +5,24 @@ class AdvanceWrestler
end end
def advance def advance
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket" if Rails.env.production?
self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Advance wrestler #{@wrestler.name} in the bracket").advance_raw
else
advance_raw
end
end end
if Rails.env.production?
handle_asynchronously :advance def advance_raw
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
end end
def pool_to_bracket_advancement def pool_to_bracket_advancement
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) and (@wrestler.finished_bracket_matches.size == 0 or @wrestler.weight.pools == 1) if @wrestler.weight.all_pool_matches_finished(@wrestler.pool) and (@wrestler.finished_bracket_matches.size == 0 or @wrestler.weight.pools == 1)
PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder
end end
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler if @wrestler.weight.all_pool_matches_finished(@wrestler.pool)
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler
end
end end
end end

View File

@@ -4,28 +4,38 @@ class GenerateTournamentMatches
end end
def generateWeight(weight) def generateWeight(weight)
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight) if Rails.env.production?
@tournament.curently_generating_matches = 1 self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Generate matches for weights class #{weight.max}").generate_weight_raw(weight)
@tournament.save else
unAssignBouts self.generate_weight_raw(weight)
unAssignMats end
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatchesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
postMatchCreationActions
PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
end end
if Rails.env.production?
handle_asynchronously :generateWeight def generate_weight_raw(weight)
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
@tournament.curently_generating_matches = 1
@tournament.save
unAssignBouts
unAssignMats
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatchesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
postMatchCreationActions
PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
end end
def generate def generate
if Rails.env.production?
self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Generate matches for all weights").generate_raw
else
self.generate_raw
end
end
def generate_raw
standardStartingActions standardStartingActions
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket" PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket"
postMatchCreationActions postMatchCreationActions
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket" PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
end end
if Rails.env.production?
handle_asynchronously :generate
end
def standardStartingActions def standardStartingActions
@tournament.curently_generating_matches = 1 @tournament.curently_generating_matches = 1

View File

@@ -7,6 +7,14 @@ class WrestlingdevImporter
end end
def import def import
if Rails.env.production?
self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Importing a backup").import_raw
else
import_raw
end
end
def import_raw
@tournament.curently_generating_matches = 1 @tournament.curently_generating_matches = 1
@tournament.save @tournament.save
destroy_all destroy_all
@@ -14,9 +22,6 @@ class WrestlingdevImporter
@tournament.curently_generating_matches = nil @tournament.curently_generating_matches = nil
@tournament.save @tournament.save
end end
if Rails.env.production?
handle_asynchronously :import
end
def destroy_all def destroy_all
@tournament.mats.reload.each do | mat | @tournament.mats.reload.each do | mat |

View File

@@ -1,30 +1,23 @@
<h3> <h3>
Info Info
</h3> </h3>
<p> <p>
<strong>Address:</strong> <strong>Address:</strong>
<%= @tournament.address %> <%= @tournament.address %>
</p> </p>
<p> <p>
<strong>Director:</strong> <strong>Director:</strong>
<%= @tournament.director %> <%= @tournament.director %>
</p> </p>
<p> <p>
<strong>Director email:</strong> <strong>Director email:</strong>
<%= @tournament.director_email %> <%= @tournament.director_email %>
</p> </p>
<p> <p>
<strong>Tournament Type:</strong> <strong>Tournament Type:</strong>
<%= @tournament.tournament_type %> <%= @tournament.tournament_type %>
</p> </p>
<br> <br>
<br>
<h3>Schools</h3> <h3>Schools</h3>
<p>(Click to see lineups, score breakdowns, and stats)</p> <p>(Click to see lineups, score breakdowns, and stats)</p>
<br> <br>
@@ -35,8 +28,6 @@
<% if can? :manage, @tournament %><th><%= link_to " New School" , "/schools/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th><% end %> <% if can? :manage, @tournament %><th><%= link_to " New School" , "/schools/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th><% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @schools.each do |school| %> <% @schools.each do |school| %>
<tr> <tr>
@@ -55,9 +46,6 @@
</tbody> </tbody>
</table> </table>
<br> <br>
<br>
<h3>Weight Class Seeds</h3> <h3>Weight Class Seeds</h3>
<br> <br>
<table class="table table-hover table-condensed"> <table class="table table-hover table-condensed">
@@ -84,7 +72,6 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% if can? :manage, @tournament %> <% if can? :manage, @tournament %>
<br> <br>
<br> <br>
@@ -96,7 +83,6 @@
<th><%= link_to " New Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th> <th><%= link_to " New Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @mats.each do |mat| %> <% @mats.each do |mat| %>
<tr> <tr>
@@ -111,7 +97,35 @@
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<br>
<h3>Background Jobs</h3>
<p>This is a list of queued or running background jobs. Match generation, bracket advancement, team score calculation, etc.</p>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Name of Job</th>
<th>Job Status</th>
</tr>
</thead>
<tbody>
<% @tournament.deferred_jobs.each do |job| %>
<tr>
<td><%= job.job_owner_type %></td>
<td>
<% if job.locked_at %>
Running
<% elsif job.last_error %>
Error
<% elsif job.attempts == 0 and !job.locked_at %>
Pending
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<br>
<br> <br>
<%= render 'import_form' %> <%= render 'import_form' %>

View File

@@ -0,0 +1,6 @@
class AddOwnerToJobs < ActiveRecord::Migration[6.0]
def change
add_column :delayed_jobs, :job_owner_id, :integer
add_column :delayed_jobs, :job_owner_type, :string
end
end