Skip to content

Commit

Permalink
Fix post threading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
minter committed Feb 9, 2025
1 parent eaa9113 commit 4af6722
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/workers/rod_the_bot/end_of_period_stats_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def perform(game_id, period_number)
shots_on_goal_post = format_post(shots_on_goal_leaders, "🏒 Shots on goal leaders", period_state)

game_splits_stats = NhlApi.splits(@game_id)
# Add timestamps to ensure uniqueness of post keys
current_date = Time.now.strftime("%Y%m%d")
game_split_stats_post = format_game_split_stats_post(game_splits_stats, period_state)
RodTheBot::Post.perform_in(180, game_split_stats_post)
RodTheBot::Post.perform_in(180, game_split_stats_post, "end_period_stats:#{@game_id}:#{current_date}")

RodTheBot::Post.perform_in(60, period_toi_post)
RodTheBot::Post.perform_in(120, shots_on_goal_post)
Expand Down
6 changes: 4 additions & 2 deletions app/workers/rod_the_bot/game_start_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def perform(game_id)
main_post = format_main_post(@feed, home_goalie, home_goalie_record, away_goalie, away_goalie_record)
reply_post = format_reply_post(officials, scratches)

main_post_key = "game_start_#{game_id}"
# Add timestamp to keys to ensure uniqueness
current_date = Time.now.strftime("%Y%m%d")
main_post_key = "game_start_#{game_id}:#{current_date}"
RodTheBot::Post.perform_async(main_post, main_post_key, nil, nil, goalie_images)
RodTheBot::Post.perform_in(1.minute, reply_post, "game_start_reply_#{game_id}", main_post_key)
RodTheBot::Post.perform_in(1.minute, reply_post, "game_start_reply_#{game_id}:#{current_date}", main_post_key)
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/workers/rod_the_bot/goal_highlight_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class GoalHighlightWorker
def perform(game_id, play_id, redis_key, initial_run_time = nil)
initial_run_time ||= Time.now.to_i

# Add timestamp to redis key to ensure uniqueness
redis_key = "#{redis_key}:#{Time.now.strftime("%Y%m%d")}" if redis_key

# Check if 6 hours have passed since the initial run
if Time.now.to_i - initial_run_time > 6.hours.to_i
logger.info "Job for game_id: #{game_id}, play_id: #{play_id} exceeded 6 hours limit. Exiting."
Expand Down
2 changes: 2 additions & 0 deletions app/workers/rod_the_bot/scoring_change_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class ScoringChangeWorker
include RodTheBot::PeriodFormatter

def perform(game_id, play_id, original_play, redis_key)
# Add timestamp to redis key to ensure uniqueness
redis_key = "#{redis_key}:#{Time.now.strftime("%Y%m%d")}" if redis_key
@feed = NhlApi.fetch_pbp_feed(game_id)
@play = @feed["plays"].find { |play| play["eventId"].to_s == play_id.to_s }
home = @feed["homeTeam"]
Expand Down
9 changes: 5 additions & 4 deletions app/workers/rod_the_bot/season_stats_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ def perform(your_team)
Points Percentage: #{season_stats_with_rank[:points_percentage][:value]} (Rank: #{season_stats_with_rank[:points_percentage][:rank]})
POST

# Generate unique keys for each post
stats_post_1_key = "season_stats:#{@season}:#{@season_type}:1"
stats_post_2_key = "season_stats:#{@season}:#{@season_type}:2"
stats_post_3_key = "season_stats:#{@season}:#{@season_type}:3"
# Generate unique keys for each post that include the current date
current_date = Time.now.strftime("%Y%m%d")
stats_post_1_key = "season_stats:#{@season}:#{@season_type}:#{current_date}:1"
stats_post_2_key = "season_stats:#{@season}:#{@season_type}:#{current_date}:2"
stats_post_3_key = "season_stats:#{@season}:#{@season_type}:#{current_date}:3"

# Schedule the posts with delays and keys
RodTheBot::Post.perform_in(30.minutes, goalie_post)
Expand Down

0 comments on commit 4af6722

Please sign in to comment.