Ruby クライアント ライブラリの各サービスには、そのサービスの client.rb ファイルで指定されたデフォルトのタイムアウト ポリシーと再試行ポリシーが付属しています。たとえば、CampaignService クライアント構成で self.configure メソッドを調べることができます。
デフォルトのタイムアウトをオーバーライドする
サービス インスタンスをインスタンス化した後、サービスレベルの config.timeout(秒単位)を設定するか、config.rpcs の個々の RPC メソッドに対して timeout と retry_policy を構成することで、これらのデフォルトをオーバーライドできます。
require 'google/ads/google_ads'
client = Google::Ads::GoogleAds::GoogleAdsClient.new
ga_service = client.service.google_ads
ga_service.configure do |config|
# Set the default timeout (in seconds) for all RPCs on this service instance.
config.timeout = 120.0
# Override the timeout or retry policy for specific RPC methods.
config.rpcs.search_stream.timeout = 300.0
config.rpcs.search.timeout = 120.0
config.rpcs.search.retry_policy = {
'initial_delay' => 5.0,
'max_delay' => 60.0
}
end
完全に動作するスクリプトについては、GitHub の set_custom_client_timeouts.rb コード例をご覧ください。
タイムアウトの制限とエラー
クライアントのタイムアウト期間を長くすることはできますが、サーバーサイドの制限は引き続き適用されます。2 時間を超えるリクエストは失敗し、DEADLINE_EXCEEDED ステータスで Google::Ads::GoogleAds::Errors::GoogleAdsError または GRPC::DeadlineExceeded 例外が発生する可能性があります。