Sha256: 68c5485698d62df5bd6d6c751c4b414ba8e1aa631902adbbf4411c9f31938787
Contents?: true
Size: 1.79 KB
Versions: 4
Compression:
Stored size: 1.79 KB
Contents
# encoding: utf-8 # Copyright 2014 Aerospike, Inc. # # Portions may be licensed to Aerospike, Inc. under one or more contributor # license agreements. # # 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. require 'thread' require 'time' require 'atomic' module Aerospike private class Task def initialize(cluster, done) @cluster = cluster @done = Atomic.new(done) @done_thread = Atomic.new(nil) self end def wait_till_completed(poll_interval = 0.1, allowed_failures = 3) return true if @done.value # make sure there will be only ONE thread polling for completetion status @done_thread.update do |dt| dt ? dt : Thread.new do abort_on_exception=true failures = 0 while true begin break if completed? sleep(poll_interval.to_f) rescue => e break if failures > allowed_failures failures += 1 end end end end # wait for the poll thread to finish @done_thread.value.join # in case of errors and exceptions, the @done value might be false @done.value end def completed? if @done.value == true true else @done.value = all_nodes_done? end end end # class end # module
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
aerospike-0.1.3 | lib/aerospike/task/task.rb |
aerospike-0.1.2 | lib/aerospike/task/task.rb |
aerospike-0.1.1 | lib/aerospike/task/task.rb |
aerospike-0.1.0 | lib/aerospike/task/task.rb |