Class: QueueryClient::Client
- Inherits:
-
Object
- Object
- QueueryClient::Client
- Defined in:
- lib/queuery_client/client.rb
Instance Method Summary collapse
- #default_options ⇒ Object
- #execute_query(select_stmt, values) ⇒ Object
- #garage_client ⇒ Object
- #get_query(id) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #options ⇒ Object
- #query(select_stmt, values) ⇒ Object
- #query_and_wait(select_stmt, values) ⇒ Object
- #wait_for(id) ⇒ 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( = {}) @options = end |
Instance Method Details
#default_options ⇒ Object
57 58 59 |
# File 'lib/queuery_client/client.rb', line 57 def QueueryClient.configuration end |
#execute_query(select_stmt, values) ⇒ Object
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) end |
#garage_client ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/queuery_client/client.rb', line 44 def garage_client @garage_client ||= BasicAuthGarageClient.new( endpoint: .endpoint, path_prefix: '/', login: .token, password: .token_secret ) end |
#get_query(id) ⇒ Object
11 12 13 |
# File 'lib/queuery_client/client.rb', line 11 def get_query(id) garage_client.get("/v1/queries/#{id}", fields: '__default__,s3_prefix') end |
#options ⇒ Object
53 54 55 |
# File 'lib/queuery_client/client.rb', line 53 def .merge(@options) end |
#query(select_stmt, values) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/queuery_client/client.rb', line 31 def query(select_stmt, values) query = query_and_wait(select_stmt, values) case query.status when 'success' UrlDataFileBundle.new( query.data_file_urls, s3_prefix: query.s3_prefix, ) when 'failed' raise QueryError.new(query.error) end end |
#query_and_wait(select_stmt, values) ⇒ Object
26 27 28 29 |
# File 'lib/queuery_client/client.rb', line 26 def query_and_wait(select_stmt, values) query = execute_query(select_stmt, values) wait_for(query.id) end |
#wait_for(id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/queuery_client/client.rb', line 15 def wait_for(id) loop do query = get_query(id) case query.status when 'success', 'failed' return query end sleep 3 end end |