Sha256: 1d6ac5021b6b7b5a6188272effe83a2d75832fe5769ba85568d2835d9a25caa2

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 KB

Contents

# Copyright 2013-2014 Aerospike, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Aerospike

	private

	# ExecuteTask is used to poll for long running server execute job completion.
	class ExecuteTask < Task

		# NewExecuteTask initializes task with fields needed to query server nodes.
		def initialize(cluster, statement)
			super(cluster, false)

			@task_id = statement.task_id
			@scan = statement.is_scan?

			self
		end

		# IsDone queries all nodes for task completion status.
		def all_nodes_done?

			if @scan 
				command = 'scan-list'
			else 
				command = 'query-list'
			end

			nodes = @cluster.nodes
			done = false

			nodes.each do |node|
				conn = node.get_connection(0)
				responseMap, err = Info.request(conn, command)
				node.put_connection(conn)

				response = responseMap[command]
				find = "job_id=#{@task_id}:"
				index = response.index(find)

				unless index
					# don't return on first check
					done = true
					next
				end

				b = index + find.length
				response = response[b, response.length]
				find = 'job_status='
				index = response.index(find)

				next unless index

				b = index + find.length
				response = response[b, response.length]
				e = response.index(':')
				status = response[0, e]

				case status 
				when 'ABORTED'
					raise raise Aerospike::Exceptions::QueryTerminated
				when 'IN PROGRESS'
					return false
				when 'DONE'
					done = true
				end
			end

			done
		end

	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aerospike-1.0.12 lib/aerospike/task/execute_task.rb
aerospike-1.0.11 lib/aerospike/task/execute_task.rb
aerospike-1.0.10 lib/aerospike/task/execute_task.rb
aerospike-1.0.9 lib/aerospike/task/execute_task.rb
aerospike-1.0.8 lib/aerospike/task/execute_task.rb
aerospike-1.0.7 lib/aerospike/task/execute_task.rb
aerospike-1.0.6 lib/aerospike/task/execute_task.rb
aerospike-1.0.5 lib/aerospike/task/execute_task.rb