diff --git a/Gemfile b/Gemfile index 9ccbede..d2d5dbd 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ gem 'spring', :group => :development gem 'cancancan' gem 'round_robin_tournament' gem 'rb-readline' + gem 'delayed_job_active_record' group :development do gem 'puma' #gem 'bullet' diff --git a/Gemfile.lock b/Gemfile.lock index d17ca7a..09a18f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,6 +49,11 @@ GEM coffee-script-source (1.9.1.1) concurrent-ruby (1.0.0) dalli (2.7.5) + delayed_job (4.1.1) + activesupport (>= 3.0, < 5.0) + delayed_job_active_record (4.1.0) + activerecord (>= 3.0, < 5) + delayed_job (>= 3.0, < 5) devise (3.4.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -162,6 +167,7 @@ DEPENDENCIES cancancan coffee-rails (~> 4.0.0) dalli + delayed_job_active_record devise jbuilder (~> 2.0) jquery-rails diff --git a/app/models/match.rb b/app/models/match.rb index 8240f0b..b83b362 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -4,6 +4,11 @@ class Match < ActiveRecord::Base belongs_to :mat, touch: true has_many :wrestlers, :through => :weight + if Rails.env.production? + handle_asynchronously :advance_wrestlers + handle_asynchronously :calcSchoolPoints + end + after_update do if self.finished == 1 && self.winner_id != nil if self.w1 && self.w2 diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 8c5e3a5..d4697fe 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -9,6 +9,10 @@ class Tournament < ActiveRecord::Base has_many :wrestlers, through: :weights has_many :matches, dependent: :destroy + if Rails.env.production? + handle_asynchronously :generateMatchups + end + def resetSchoolScores schools.update_all("score = 0.0") end diff --git a/app/views/tournaments/generate_matches.html.erb b/app/views/tournaments/generate_matches.html.erb index 469b04c..ba0cac2 100644 --- a/app/views/tournaments/generate_matches.html.erb +++ b/app/views/tournaments/generate_matches.html.erb @@ -1,3 +1,3 @@ <%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>

-Matches successfully generated. \ No newline at end of file +Matches are being generated. This can take anywhere from 1-5 minutes to finish. \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 34a0e94..9fb08b3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,6 +26,7 @@ module Wrestling config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) #gzip assets config.middleware.use Rack::Deflater + config.active_job.queue_adapter = :delayed_job end