mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-24 17:04:43 +00:00
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
class TournamentBackupJob < ApplicationJob
|
|
queue_as :default
|
|
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
|
|
|
|
def perform(tournament, reason = nil)
|
|
# Log information about the job
|
|
Rails.logger.info("Creating backup for tournament ##{tournament.id} (#{tournament.name}), reason: #{reason || 'manual'}")
|
|
|
|
# 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
|