Class: Ath::Query
- Inherits:
-
Object
- Object
- Ath::Query
- Defined in:
- lib/ath/query.rb
Instance Method Summary collapse
-
#initialize(shell:, query:, detach: false) ⇒ Query
constructor
A new instance of Query.
- #run ⇒ Object
Constructor Details
#initialize(shell:, query:, detach: false) ⇒ Query
Returns a new instance of Query.
2 3 4 5 6 |
# File 'lib/ath/query.rb', line 2 def initialize(shell:, query:, detach: false) @shell = shell @query = query @detach = detach end |
Instance Method Details
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 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 46 |
# File 'lib/ath/query.rb', line 8 def run query_execution_id = @shell.driver.start_query_execution( query_string: @query, database: @shell.database, output_location: @shell..fetch(:output_location) ).query_execution_id if @detach return "QueryExecution #{query_execution_id}" end abort_waiting = false orig_handler = trap(:INT, proc { abort_waiting = true }) query_execution = nil begin until abort_waiting query_execution = @shell.driver.get_query_execution(query_execution_id: query_execution_id) if query_execution.status.completion_date_time break end sleep 1 end ensure trap(:INT, orig_handler) end if abort_waiting return "QueryExecution #{query_execution_id}: Detach query" end if query_execution.status.state == 'SUCCEEDED' @shell.driver.get_query_execution_result(query_execution_id: query_execution_id) else "QueryExecution #{query_execution_id}: #{query_execution.status.state_change_reason}" end end |