Add Elo rating system with match entry and CSV upload
- Implement EloCalculator service for 2v2 Euchre matches - Create background job processing with GoodJob - Add single match entry form - Add CSV upload for batch match entry - Create player rankings view - Add database schema for matches and elo snapshots
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../config/app"
|
||||
|
||||
# Boot the Hanami app to ensure persistence is available
|
||||
EuchreCamp::App.boot
|
||||
|
||||
# Simple worker that polls for jobs and executes them
|
||||
def poll_and_execute_jobs
|
||||
rom = EuchreCamp::App["persistence.rom"]
|
||||
|
||||
puts "Worker started, waiting for jobs..."
|
||||
|
||||
loop do
|
||||
# Find a pending job
|
||||
job = rom.relations[:good_jobs].where(finished_at: nil).order(:scheduled_at).limit(1).one
|
||||
|
||||
if job
|
||||
begin
|
||||
# Mark as performed
|
||||
rom.relations[:good_jobs].where(id: job[:id]).update(
|
||||
performed_at: Time.now,
|
||||
executions_count: (job[:executions_count] || 0) + 1
|
||||
)
|
||||
|
||||
# Execute the job
|
||||
params = JSON.parse(job[:serialized_params])
|
||||
job_class = Object.const_get(job[:job_class])
|
||||
|
||||
if params["match_id"]
|
||||
job_class.perform(params["match_id"])
|
||||
else
|
||||
# Legacy format for backwards compatibility
|
||||
job_class.perform(*params["arguments"])
|
||||
end
|
||||
|
||||
# Mark as finished
|
||||
rom.relations[:good_jobs].where(id: job[:id]).update(finished_at: Time.now)
|
||||
|
||||
puts "Executed job #{job[:id]}: #{job[:job_class]}"
|
||||
rescue => e
|
||||
# Mark as failed
|
||||
rom.relations[:good_jobs].where(id: job[:id]).update(
|
||||
finished_at: Time.now,
|
||||
error: e.message
|
||||
)
|
||||
puts "Failed job #{job[:id]}: #{e.message}"
|
||||
puts e.backtrace.first(5).join("\n")
|
||||
end
|
||||
else
|
||||
# No jobs, wait a bit
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
poll_and_execute_jobs
|
||||
Reference in New Issue
Block a user