Class: Embulk::Output::Bigquery::GoogleClient
- Inherits:
-
Object
- Object
- Embulk::Output::Bigquery::GoogleClient
- Defined in:
- lib/embulk/output/bigquery/google_client.rb
Direct Known Subclasses
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(task, scope, client_class) ⇒ GoogleClient
constructor
A new instance of GoogleClient.
-
#with_network_retry(&block) ⇒ Object
google-api-ruby-client itself has a retry feature, but it does not retry with SocketException.
Constructor Details
#initialize(task, scope, client_class) ⇒ GoogleClient
Returns a new instance of GoogleClient.
14 15 16 17 18 19 |
# File 'lib/embulk/output/bigquery/google_client.rb', line 14 def initialize(task, scope, client_class) @task = task @scope = scope @auth = Auth.new(task, scope) @client_class = client_class end |
Instance Method Details
#client ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/embulk/output/bigquery/google_client.rb', line 21 def client return @cached_client if @cached_client && @cached_client_expiration > Time.now client = @client_class.new client..application_name = @task['application_name'] client..retries = @task['retries'] if client..respond_to?(:timeout_sec) client..timeout_sec = @task['timeout_sec'] || 300 client..open_timeout_sec = @task['open_timeout_sec'] || 300 else # google-api-ruby-client >= v0.11.0 if @task['timeout_sec'] Embulk.logger.warn { "embulk-output-bigquery: timeout_sec is deprecated in google-api-ruby-client >= v0.11.0. Use read_timeout_sec instead" } end client..open_timeout_sec = @task['open_timeout_sec'] || 300 # default: 60 client..send_timeout_sec = @task['send_timeout_sec'] || 300 # default: 120 client..read_timeout_sec = @task['read_timeout_sec'] || @task['timeout_sec'] || 300 # default: 60 end Embulk.logger.debug { "embulk-output-bigquery: client_options: #{client..to_h}" } Embulk.logger.debug { "embulk-output-bigquery: request_options: #{client..to_h}" } client. = @auth.authenticate @cached_client_expiration = Time.now + 1800 @cached_client = client end |
#with_network_retry(&block) ⇒ Object
google-api-ruby-client itself has a retry feature, but it does not retry with SocketException
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/embulk/output/bigquery/google_client.rb', line 48 def with_network_retry(&block) retries = 0 begin yield rescue ::Java::Java.net.SocketException, ::Java::Java.net.ConnectException, ::Java::JavaxNetSsl::SSLException => e = [ 'Broken pipe', 'Connection reset', 'Connection timed out', 'Connection or outbound has closed', ] if .select { |x| e..include?(x) }.empty? raise e else if retries < @task['retries'] retries += 1 Embulk.logger.warn { "embulk-output-bigquery: retry \##{retries}, #{e.class} #{e.}" } retry else Embulk.logger.error { "embulk-output-bigquery: retry exhausted \##{retries}, #{e.class} #{e.}" } raise e end end end end |