Skip to content

Commit

Permalink
MLB-298 Markets are not finished on stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeykot authored and Andrew-Easternpeak committed Jun 18, 2014
1 parent 9b00638 commit a5a4725
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions chef/cookbooks/mustwin-basics/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@
end
end

if node['easternpeak']['roles'].include?('WORKER')
execute 'Flush Redis' do
command 'redis-cli flushall'
end
end

node['easternpeak']['roles'].each do |role, b|
node['easternpeak']['services'][role].each do |service|
# TODO: FIGURE OUT GOD, DAMMIT
Expand Down
25 changes: 15 additions & 10 deletions webapp/app/workers/game_stat_fetcher_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ class GameStatFetcherWorker
60*15
end

sidekiq_retries_exhausted do |msg|
game = Game.find_by_stats_id msg['args'][0]
game.update_attributes(:status =>'cancelled', :checked => true) if game.stat_events.empty?
game.markets.each { |m| m.individual_predictions.each(&:cancel!) }
game.markets.each { |m| m.rosters.each { |r| r.cancel!('game postponed') } }
end
sidekiq_retries_exhausted { |msg| cancel_predictions(msg['args'][0]) }

# See PBP Play type doc part for MLB

Expand Down Expand Up @@ -110,10 +105,13 @@ def perform(game_stat_id)

data = data.first

if game.status.try(:downcase) == 'postponed' or game.status == 'cancelled'
return unless data.present?
else
raise unless data.present?
unless data.present?
if game.status.try(:downcase) == 'postponed' or game.status == 'cancelled' or (Time.now.utc - game.game_time.utc > 5.hours)
cancel_predictions(game_stat_id)
return
else
raise
end
end

played_players_ids = []
Expand Down Expand Up @@ -228,4 +226,11 @@ def find_or_create_stat_event(player_stats_id, game, action, quantity)
st.data = ''
st.save!
end

def cancel_predictions(game_stats_id)
game = Game.find_by_stats_id game_stats_id
game.update_attributes(:status =>'cancelled', :checked => true) if game.stat_events.empty?
game.markets.each { |m| m.individual_predictions.where.not(state: ['finished', 'canceled']).each(&:cancel!) }
game.markets.each { |m| m.rosters.each { |r| r.cancel!('game postponed') } }
end
end
2 changes: 1 addition & 1 deletion webapp/app/workers/unfetched_games_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class UnfetchedGamesWorker
sidekiq_options :queue => :unfetched_games_worker

def perform
Game.where(:sport_id => SportStrategy.for('MLB').sport.id).select { |g| g.game_time < Time.now and g.game_time.year == 2014 and g.stat_events.empty? and g.status.to_s.downcase != 'postponed' }.uniq.each { |i| GameStatFetcherWorker.perform_async i.stats_id }
Game.where(:sport_id => SportStrategy.for('MLB').sport.id, :checked => nil).select { |g| g.game_time < Time.now and g.game_time.year == 2014 and g.stat_events.empty? and g.status.to_s.downcase != 'postponed' }.uniq.each { |i| GameStatFetcherWorker.perform_async i.stats_id }
end
end
2 changes: 1 addition & 1 deletion webapp/config/initializers/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if is_worker
#$redis.flushall
#Sidekiq::Monitor::Job.delete_all
GameListener.perform_async unless $redis.get('listener_working') == 'true'
GameListener.perform_async and UnfetchedGamesWorker.perform_async unless $redis.get('listener_working') == 'true'

schedule_file = 'config/schedule.yml'

Expand Down

0 comments on commit a5a4725

Please sign in to comment.