Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/bundler/net-smtp-0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
minter authored Feb 11, 2025
2 parents d6094a3 + 6f82e79 commit c66b227
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion 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

# Store the original redis_key before adding timestamp
original_redis_key = redis_key

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

Expand Down Expand Up @@ -35,7 +38,8 @@ def perform(game_id, play_id, redis_key, initial_run_time = nil)
RodTheBot::Post.perform_async(post, redis_key, nil, nil, [], output_path)
end
else
self.class.perform_in(3.minutes, game_id, play_id, redis_key, initial_run_time)
# Use original_redis_key when rescheduling
self.class.perform_in(3.minutes, game_id, play_id, original_redis_key, initial_run_time)
end
end

Expand Down
15 changes: 8 additions & 7 deletions test/workers/rod_the_bot/goal_highlight_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase

setup do
@game_id = "2024010043"
@redis_key = "game:#{@game_id}:goal:157"
@base_redis_key = "game:#{@game_id}:goal:157"
@redis_key = "#{@base_redis_key}:#{Time.now.strftime("%Y%m%d")}"
VCR.use_cassette("nhl_api_#{@game_id}") do
@pbp_feed = NhlApi.fetch_pbp_feed(@game_id)
@landing_feed = NhlApi.fetch_landing_feed(@game_id)
Expand All @@ -31,7 +32,7 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase
)

assert_no_enqueued_jobs(only: RodTheBot::GoalHighlightWorker) do
RodTheBot::GoalHighlightWorker.new.perform(@game_id, @play_id, @redis_key)
RodTheBot::GoalHighlightWorker.new.perform(@game_id, @play_id, @base_redis_key)
end
end
end
Expand Down Expand Up @@ -59,11 +60,11 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase
worker = RodTheBot::GoalHighlightWorker.new

assert_difference -> { RodTheBot::GoalHighlightWorker.jobs.size }, 1 do
worker.perform(@game_id, @play_id, @redis_key)
worker.perform(@game_id, @play_id, @base_redis_key)
end

job = RodTheBot::GoalHighlightWorker.jobs.last
assert_equal [@game_id, @play_id, @redis_key], job["args"][0..2]
assert_equal [@game_id, @play_id, @base_redis_key], job["args"][0..2]
assert_in_delta Time.now.to_i, job["args"][3], 1
assert_in_delta 3.minutes.from_now.to_i, job["at"], 1
end
Expand All @@ -77,7 +78,7 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase
RodTheBot::Post.expects(:perform_async).never

assert_no_difference -> { RodTheBot::GoalHighlightWorker.jobs.size } do
RodTheBot::GoalHighlightWorker.new.perform(@game_id, non_goal_play_id, @redis_key)
RodTheBot::GoalHighlightWorker.new.perform(@game_id, non_goal_play_id, @base_redis_key)
end
end
end
Expand Down Expand Up @@ -110,7 +111,7 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase
"spec/fixtures/test_video.mp4"
)

worker.perform(@game_id, @play_id, @redis_key)
worker.perform(@game_id, @play_id, @base_redis_key)
end
end

Expand All @@ -121,7 +122,7 @@ class RodTheBot::GoalHighlightWorkerTest < ActiveSupport::TestCase

assert_no_difference -> { RodTheBot::GoalHighlightWorker.jobs.size } do
worker = RodTheBot::GoalHighlightWorker.new
worker.perform(@game_id, @play_id, @redis_key, initial_run_time)
worker.perform(@game_id, @play_id, @base_redis_key, initial_run_time)
end
end
end

0 comments on commit c66b227

Please sign in to comment.