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:
@@ -31,13 +31,19 @@ class School < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def calculate_score
|
||||
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.save
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :calculate_score
|
||||
end
|
||||
|
||||
def total_points_scored_by_wrestlers
|
||||
points = 0
|
||||
|
||||
@@ -12,6 +12,10 @@ class Tournament < ActiveRecord::Base
|
||||
|
||||
attr_accessor :import_text
|
||||
|
||||
def deferred_jobs
|
||||
Delayed::Job.where(job_owner_id: self.id)
|
||||
end
|
||||
|
||||
def self.search(search)
|
||||
where("date LIKE ? or name LIKE ?", "%#{search}%", "%#{search}%")
|
||||
end
|
||||
|
||||
@@ -5,17 +5,24 @@ class AdvanceWrestler
|
||||
end
|
||||
|
||||
def advance
|
||||
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :advance
|
||||
self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Advance wrestler #{@wrestler.name} in the bracket").advance_raw
|
||||
else
|
||||
advance_raw
|
||||
end
|
||||
end
|
||||
|
||||
def advance_raw
|
||||
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
|
||||
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)
|
||||
PoolOrder.new(@wrestler.weight.wrestlers_in_pool(@wrestler.pool)).getPoolOrder
|
||||
end
|
||||
if @wrestler.weight.all_pool_matches_finished(@wrestler.pool)
|
||||
PoolAdvance.new(@wrestler,@wrestler.last_match).advanceWrestler
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,6 +4,14 @@ class GenerateTournamentMatches
|
||||
end
|
||||
|
||||
def generateWeight(weight)
|
||||
if Rails.env.production?
|
||||
self.delay(:job_owner_id => @tournament.id, :job_owner_type => "Generate matches for weights class #{weight.max}").generate_weight_raw(weight)
|
||||
else
|
||||
self.generate_weight_raw(weight)
|
||||
end
|
||||
end
|
||||
|
||||
def generate_weight_raw(weight)
|
||||
WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
|
||||
@tournament.curently_generating_matches = 1
|
||||
@tournament.save
|
||||
@@ -13,19 +21,21 @@ class GenerateTournamentMatches
|
||||
postMatchCreationActions
|
||||
PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :generateWeight
|
||||
end
|
||||
|
||||
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
|
||||
PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatches if @tournament.tournament_type == "Pool to bracket"
|
||||
postMatchCreationActions
|
||||
PoolToBracketMatchGeneration.new(@tournament).assignLoserNames if @tournament.tournament_type == "Pool to bracket"
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :generate
|
||||
end
|
||||
|
||||
def standardStartingActions
|
||||
@tournament.curently_generating_matches = 1
|
||||
|
||||
@@ -7,6 +7,14 @@ class WrestlingdevImporter
|
||||
end
|
||||
|
||||
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.save
|
||||
destroy_all
|
||||
@@ -14,9 +22,6 @@ class WrestlingdevImporter
|
||||
@tournament.curently_generating_matches = nil
|
||||
@tournament.save
|
||||
end
|
||||
if Rails.env.production?
|
||||
handle_asynchronously :import
|
||||
end
|
||||
|
||||
def destroy_all
|
||||
@tournament.mats.reload.each do | mat |
|
||||
|
||||
@@ -1,30 +1,23 @@
|
||||
<h3>
|
||||
Info
|
||||
</h3>
|
||||
|
||||
<p>
|
||||
<strong>Address:</strong>
|
||||
<%= @tournament.address %>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
<strong>Director:</strong>
|
||||
<%= @tournament.director %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Director email:</strong>
|
||||
<%= @tournament.director_email %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Tournament Type:</strong>
|
||||
<%= @tournament.tournament_type %>
|
||||
</p>
|
||||
<br>
|
||||
<br>
|
||||
<h3>Schools</h3>
|
||||
<p>(Click to see lineups, score breakdowns, and stats)</p>
|
||||
<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 %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<% @schools.each do |school| %>
|
||||
<tr>
|
||||
@@ -55,9 +46,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
|
||||
<h3>Weight Class Seeds</h3>
|
||||
<br>
|
||||
<table class="table table-hover table-condensed">
|
||||
@@ -84,7 +72,6 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<% if can? :manage, @tournament %>
|
||||
<br>
|
||||
<br>
|
||||
@@ -96,7 +83,6 @@
|
||||
<th><%= link_to " New Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"fas fa-plus" %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @mats.each do |mat| %>
|
||||
<tr>
|
||||
@@ -111,7 +97,35 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<% 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>
|
||||
<%= render 'import_form' %>
|
||||
|
||||
|
||||
6
db/migrate/20191126174257_add_owner_to_jobs.rb
Normal file
6
db/migrate/20191126174257_add_owner_to_jobs.rb
Normal 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
|
||||
Reference in New Issue
Block a user