1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-01 12:15:25 +00:00

Fixed reset password after the Devise migration.

This commit is contained in:
2025-04-14 14:25:40 -04:00
parent 4828d9b876
commit 01a499cc45
18 changed files with 383 additions and 158 deletions

View File

@@ -9,8 +9,31 @@ class AdvanceWrestlerJob < ApplicationJob
end
def perform(wrestler, match)
# Execute the job
service = AdvanceWrestler.new(wrestler, match)
service.advance_raw
# Get tournament from wrestler
tournament = wrestler.tournament
# Create job status record
job_name = "Advancing wrestler #{wrestler.name}"
job_status = TournamentJobStatus.create!(
tournament: tournament,
job_name: job_name,
status: "Running",
details: "Match ID: #{match.bout_number}"
)
begin
# Execute the job
service = AdvanceWrestler.new(wrestler, match)
service.advance_raw
# Remove the job status record on success
TournamentJobStatus.complete_job(tournament.id, job_name)
rescue => e
# Update status to errored
job_status.update(status: "Errored", details: "Error: #{e.message}")
# Re-raise the error for SolidQueue to handle
raise e
end
end
end

View File

@@ -11,7 +11,28 @@ class CalculateSchoolScoreJob < ApplicationJob
# Log information about the job
Rails.logger.info("Calculating score for school ##{school.id} (#{school.name})")
# Execute the calculation
school.calculate_score_raw
# Create job status record
tournament = school.tournament
job_name = "Calculating team score for #{school.name}"
job_status = TournamentJobStatus.create!(
tournament: tournament,
job_name: job_name,
status: "Running",
details: "School ID: #{school.id}"
)
begin
# Execute the calculation
school.calculate_score_raw
# Remove the job status record on success
TournamentJobStatus.complete_job(tournament.id, job_name)
rescue => e
# Update status to errored
job_status.update(status: "Errored", details: "Error: #{e.message}")
# Re-raise the error for SolidQueue to handle
raise e
end
end
end

View File

@@ -12,8 +12,28 @@ class TournamentBackupJob < ApplicationJob
# Log information about the job
Rails.logger.info("Creating backup for tournament ##{tournament.id} (#{tournament.name}), reason: #{reason || 'manual'}")
# Execute the backup
service = TournamentBackupService.new(tournament, reason)
service.create_backup_raw
# Create job status record
job_name = "Backing up tournament"
job_status = TournamentJobStatus.create!(
tournament: tournament,
job_name: job_name,
status: "Running",
details: "Reason: #{reason || 'manual'}"
)
begin
# Execute the backup
service = TournamentBackupService.new(tournament, reason)
service.create_backup_raw
# Remove the job status record on success
TournamentJobStatus.complete_job(tournament.id, job_name)
rescue => e
# Update status to errored
job_status.update(status: "Errored", details: "Error: #{e.message}")
# Re-raise the error for SolidQueue to handle
raise e
end
end
end

View File

@@ -13,9 +13,29 @@ class WrestlingdevImportJob < ApplicationJob
# Log information about the job
Rails.logger.info("Starting import for tournament ##{tournament.id} (#{tournament.name})")
# Execute the import
importer = WrestlingdevImporter.new(tournament)
importer.import_data = import_data if import_data
importer.import_raw
# Create job status record
job_name = "Importing tournament"
job_status = TournamentJobStatus.create!(
tournament: tournament,
job_name: job_name,
status: "Running",
details: "Processing backup data"
)
begin
# Execute the import
importer = WrestlingdevImporter.new(tournament)
importer.import_data = import_data if import_data
importer.import_raw
# Remove the job status record on success
TournamentJobStatus.complete_job(tournament.id, job_name)
rescue => e
# Update status to errored
job_status.update(status: "Errored", details: "Error: #{e.message}")
# Re-raise the error for SolidQueue to handle
raise e
end
end
end

View File

@@ -9,6 +9,7 @@ class Tournament < ApplicationRecord
has_many :delegates, class_name: "TournamentDelegate"
has_many :mat_assignment_rules, dependent: :destroy
has_many :tournament_backups, dependent: :destroy
has_many :tournament_job_statuses, dependent: :destroy
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
@@ -263,6 +264,16 @@ class Tournament < ApplicationRecord
return error_string.blank?
end
# Check if there are any active jobs for this tournament
def has_active_jobs?
tournament_job_statuses.active.exists?
end
# Get all active jobs for this tournament
def active_jobs
tournament_job_statuses.active
end
private
def connection_adapter

View File

@@ -0,0 +1,20 @@
class TournamentJobStatus < ApplicationRecord
belongs_to :tournament
# Validations
validates :job_name, presence: true
validates :status, presence: true, inclusion: { in: ["Queued", "Running", "Errored"] }
# Scopes
scope :active, -> { where.not(status: "Errored") }
# Class methods to find jobs for a tournament
def self.for_tournament(tournament)
where(tournament_id: tournament.id)
end
# Clean up completed jobs (should be called when job finishes successfully)
def self.complete_job(tournament_id, job_name)
where(tournament_id: tournament_id, job_name: job_name).destroy_all
end
end

View File

@@ -9,6 +9,19 @@
</div>
<% end %>
<% if (can? :manage, @tournament) && @tournament.has_active_jobs? %>
<div class="alert alert-info">
<strong>Background Jobs In Progress</strong>
<p>The following background jobs are currently running:</p>
<ul>
<% @tournament.active_jobs.each do |job| %>
<li><%= job.job_name %> - <%= job.status %> <%= "(#{job.details})" if job.details.present? %></li>
<% end %>
</ul>
<p>Please refresh the page to check progress.</p>
</div>
<% end %>
<p>
<strong>Address:</strong>
<%= @tournament.address %>