Skip to content

Commit d7b6bc0

Browse files
iHiDclaude
andauthored
Retry GitHub solution sync on transient server errors (#8468)
Rescue Octokit::ServerError (covers BadGateway, InternalServerError, ServiceUnavailable) in the sync commands and requeue the job after 30 seconds, matching the existing requeue pattern used for Discord rate limits. Closes #8457 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c71086c commit d7b6bc0

8 files changed

Lines changed: 70 additions & 0 deletions

File tree

app/commands/user/github_solution_syncer/sync_everything.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def call
1717
end
1818
rescue GithubApp::InstallationNotFoundError
1919
# noop - installation may have been removed or GitHub may be having issues
20+
rescue Octokit::ServerError
21+
requeue_job!(30.seconds)
2022
end
2123

2224
def sync_everything(branch_name, token = nil)

app/commands/user/github_solution_syncer/sync_iteration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def call
2020
end
2121
rescue GithubApp::InstallationNotFoundError
2222
# noop - installation may have been removed or GitHub may be having issues
23+
rescue Octokit::ServerError
24+
requeue_job!(30.seconds)
2325
end
2426

2527
private

app/commands/user/github_solution_syncer/sync_solution.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def call
1717
end
1818
rescue GithubApp::InstallationNotFoundError
1919
# noop - installation may have been removed or GitHub may be having issues
20+
rescue Octokit::ServerError
21+
requeue_job!(30.seconds)
2022
end
2123

2224
private

app/commands/user/github_solution_syncer/sync_track.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def call
1717
end
1818
rescue GithubApp::InstallationNotFoundError
1919
# noop - installation may have been removed or GitHub may be having issues
20+
rescue Octokit::ServerError
21+
requeue_job!(30.seconds)
2022
end
2123

2224
private

test/commands/user/github_solution_syncer/sync_everything_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,18 @@ class SyncEverythingTest < ActiveSupport::TestCase
1111
# Should not raise
1212
User::GithubSolutionSyncer::SyncEverything.(user)
1313
end
14+
15+
test "requeues on server error" do
16+
user = create(:user)
17+
create(:user_github_solution_syncer, user:)
18+
19+
CreatePullRequest.stubs(:call).raises(Octokit::ServerError)
20+
21+
Mocha::Configuration.override(stubbing_non_existent_method: :allow) do
22+
cmd = User::GithubSolutionSyncer::SyncEverything.new(user)
23+
cmd.expects(:requeue_job!).with(30.seconds)
24+
cmd.()
25+
end
26+
end
1427
end
1528
end

test/commands/user/github_solution_syncer/sync_iteration_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,23 @@ class SyncIterationTest < ActiveSupport::TestCase
1616
# Should not raise
1717
User::GithubSolutionSyncer::SyncIteration.(iteration)
1818
end
19+
20+
test "requeues on server error" do
21+
user = create(:user)
22+
track = create(:track, slug: "ruby")
23+
exercise = create(:practice_exercise, track:, slug: "two-fer")
24+
solution = create(:practice_solution, user:, exercise:)
25+
submission = create(:submission, solution:)
26+
iteration = create(:iteration, user:, solution:, submission:)
27+
create(:user_github_solution_syncer, user:)
28+
29+
CreatePullRequest.stubs(:call).raises(Octokit::ServerError)
30+
31+
Mocha::Configuration.override(stubbing_non_existent_method: :allow) do
32+
cmd = User::GithubSolutionSyncer::SyncIteration.new(iteration)
33+
cmd.expects(:requeue_job!).with(30.seconds)
34+
cmd.()
35+
end
36+
end
1937
end
2038
end

test/commands/user/github_solution_syncer/sync_solution_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,21 @@ class SyncSolutionTest < ActiveSupport::TestCase
1414
# Should not raise
1515
User::GithubSolutionSyncer::SyncSolution.(solution)
1616
end
17+
18+
test "requeues on server error" do
19+
user = create(:user)
20+
track = create(:track, slug: "ruby")
21+
exercise = create(:practice_exercise, track:, slug: "two-fer")
22+
solution = create(:practice_solution, user:, exercise:)
23+
create(:user_github_solution_syncer, user:)
24+
25+
CreatePullRequest.stubs(:call).raises(Octokit::ServerError)
26+
27+
Mocha::Configuration.override(stubbing_non_existent_method: :allow) do
28+
cmd = User::GithubSolutionSyncer::SyncSolution.new(solution)
29+
cmd.expects(:requeue_job!).with(30.seconds)
30+
cmd.()
31+
end
32+
end
1733
end
1834
end

test/commands/user/github_solution_syncer/sync_track_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,20 @@ class SyncTrackTest < ActiveSupport::TestCase
1313
# Should not raise
1414
User::GithubSolutionSyncer::SyncTrack.(user_track)
1515
end
16+
17+
test "requeues on server error" do
18+
user = create(:user)
19+
track = create(:track, slug: "ruby")
20+
user_track = create(:user_track, user:, track:)
21+
create(:user_github_solution_syncer, user:)
22+
23+
CreatePullRequest.stubs(:call).raises(Octokit::ServerError)
24+
25+
Mocha::Configuration.override(stubbing_non_existent_method: :allow) do
26+
cmd = User::GithubSolutionSyncer::SyncTrack.new(user_track)
27+
cmd.expects(:requeue_job!).with(30.seconds)
28+
cmd.()
29+
end
30+
end
1631
end
1732
end

0 commit comments

Comments
 (0)