Class: QueueryClient::Client
- Inherits:
-
Object
- Object
- QueueryClient::Client
- Defined in:
- lib/queuery_client/client.rb
Constant Summary collapse
- MAX_POLLING_INTERVAL =
30
Instance Method Summary collapse
- #default_options ⇒ Object
- #execute_query(select_stmt, values, query_options) ⇒ Object (also: #start_query)
- #garage_client ⇒ Object
- #get_query(id, query_options) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #options ⇒ Object
-
#poll_result(id) ⇒ Object
poll_result returns the results only if the query has already successed.
- #query(select_stmt, values, **query_options) ⇒ Object
- #query_and_wait(select_stmt, values, query_options) ⇒ Object
- #wait_for(id, query_options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
3 4 5 |
# File 'lib/queuery_client/client.rb', line 3 def initialize( = {}) = end |
Instance Method Details
#default_options ⇒ Object
78 79 80 |
# File 'lib/queuery_client/client.rb', line 78 def QueueryClient.configuration end |
#execute_query(select_stmt, values, query_options) ⇒ Object Also known as: start_query
7 8 9 |
# File 'lib/queuery_client/client.rb', line 7 def execute_query(select_stmt, values, ) garage_client.post("/v1/queries", q: select_stmt, values: values, enable_metadata: [:enable_cast]) end |
#garage_client ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/queuery_client/client.rb', line 63 def garage_client @garage_client ||= BasicAuthGarageClient.new( endpoint: .endpoint, path_prefix: '/', login: .token, password: .token_secret ).tap do |client| client.headers['Host'] = .host_header if .host_header end end |
#get_query(id, query_options) ⇒ Object
12 13 14 15 |
# File 'lib/queuery_client/client.rb', line 12 def get_query(id, ) query_option_fields = build_query_option_fields() garage_client.get("/v1/queries/#{id}", fields: '__default__,s3_prefix' + query_option_fields) end |
#options ⇒ Object
74 75 76 |
# File 'lib/queuery_client/client.rb', line 74 def .merge() end |
#poll_result(id) ⇒ Object
poll_result returns the results only if the query has already successed.
58 59 60 61 |
# File 'lib/queuery_client/client.rb', line 58 def poll_result(id) query = get_query(id) get_query_result(query) end |
#query(select_stmt, values, **query_options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/queuery_client/client.rb', line 42 def query(select_stmt, values, **) query = query_and_wait(select_stmt, values, ) manifest_file_url = query.manifest_file_url if [:enable_cast] case query.status when 'success' UrlDataFileBundle.new( query.data_file_urls, manifest_file_url, s3_prefix: query.s3_prefix, ) when 'failed' raise QueryError.new(query.error) end end |
#query_and_wait(select_stmt, values, query_options) ⇒ Object
37 38 39 40 |
# File 'lib/queuery_client/client.rb', line 37 def query_and_wait(select_stmt, values, ) query = execute_query(select_stmt, values, ) wait_for(query.id, ) end |
#wait_for(id, query_options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/queuery_client/client.rb', line 19 def wait_for(id, ) n = 1 loop do begin query = get_query(id, ) case query.status when 'success', 'failed' return query end rescue GarageClient::GatewayTimeout warn "#{$PROGRAM_NAME}: warning: queuery polling timeout occurred" end polling_interval = [3 * n, MAX_POLLING_INTERVAL].min sleep polling_interval n += 1 end end |