Ruby クライアント ライブラリの各サービスには、そのサービスの client.rb
ファイルで指定されたデフォルトのタイムアウトと再試行ポリシーが付属しています。たとえば、
クライアント構成の
CampaignServiceself.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
完全な動作スクリプトについては、
set_custom_client_timeouts.rbコードサンプルを
GitHub でご覧ください。
タイムアウトの制限とエラー
クライアントのタイムアウト時間を増やすことはできますが、サーバーサイドの制限は適用されます。2 時間以上かかるリクエストは失敗し、DEADLINE_EXCEEDED ステータスの Google::Ads::GoogleAds::Errors::GoogleAdsError 例外または GRPC::DeadlineExceeded 例外が発生する可能性があります。