Doorkeeper API の504エラーに対するリトライ処理とタイムアウト設定を追加#1798
Merged
Conversation
## 変更内容 ### 1. タイムアウト設定の追加 (lib/event_service/client.rb) - 接続タイムアウト: 10秒 - 読み取りタイムアウト: 60秒 - 無限待機を防止 ### 2. サーバーエラーのリトライ処理 (lib/event_service/providers/doorkeeper.rb) - 502/503/504エラーを検出して自動リトライ - Exponential backoff: 10秒 → 20秒 → 40秒 - 最大3回までリトライ - group_id を含む詳細なエラーログ ### 3. 詳細なログ出力 (lib/statistics/tasks/doorkeeper.rb) - どのDojoを処理中かを表示 - 取得成功時のイベント数を表示 - エラー発生時にDojo名とgroup_idを記録 ## 動作確認 ローカル環境で以下のタスクを実行し、正常動作を確認: - `bundle exec rails statistics:aggregation` - 51個のDojoを正常に処理 - `bundle exec rails upcoming_events:aggregation` - Connpass: 116イベント取得 - Doorkeeper: 2箇所で504エラー発生 → リトライで成功 ## テスト 全216テストが成功: ``` bundle exec rspec spec 216 examples, 0 failures ``` ## 関連Issue 統計/地図スクリプトの504エラーに対応
yasulab
added a commit
that referenced
this pull request
Jan 21, 2026
リトライ回数と待機時間を短縮し、Heroku Scheduler での実行時間を削減 ## 変更内容 - リトライ回数: 3回 → 2回 に削減 - バックオフ時間: 10秒 → 20秒 → 40秒 から 5秒 → 10秒 に短縮 - 合計待機時間: 最大70秒 → 最大15秒 ## 最悪ケースの想定実行時間 以前: 51 Dojos × (60秒 × 3回 + 70秒) = 約213分(3.5時間) 改善後: 51 Dojos × (60秒 × 2回 + 15秒) = 約115分(2時間) Heroku Scheduler の実行時間制限を考慮し、一時的なエラーには十分対応しつつ、 完全ダウン時の無駄な待機時間を削減。 ## テスト 全 216 テストが成功: `bundle exec rspec spec` 216 examples, 0 failures 関連: #1798
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Doorkeeper API で発生する 504 Gateway Timeout エラーに対応するため、リトライ処理とタイムアウト設定を追加しました。
問題
統計/地図スクリプト(
rails statistics:aggregation)が Doorkeeper API の 504 エラーで失敗していました。エラーログ:
解決策
1. タイムアウト設定の追加 (
lib/event_service/client.rb)2. サーバーエラーのリトライ処理 (
lib/event_service/providers/doorkeeper.rb)group_idを含む詳細なログを出力3. 詳細なログ出力 (
lib/statistics/tasks/doorkeeper.rb)group_idを記録動作確認
ローカル環境で以下のタスクを実行し、正常動作を確認:
bundle exec rails statistics:aggregationbundle exec rails upcoming_events:aggregation重要: 2箇所で一時的に 504 エラーが発生しましたが、リトライ処理により自動的に回復し、正常に完了しました。
テスト
全 216 テストが成功:
bundle exec rspec spec 216 examples, 0 failures影響範囲
lib/event_service/client.rb: 全ての外部 API クライアントにタイムアウト設定が適用lib/event_service/providers/doorkeeper.rb: Doorkeeper API 専用のリトライ処理lib/statistics/tasks/doorkeeper.rb: 統計タスクのログ改善備考