class Mongo::Cluster::PeriodicExecutor
A manager that calls execute
on its executors at a regular interval.
@api private
@since 2.5.0
Constants
- FREQUENCY
The default time interval for the periodic executor to execute.
@since 2.5.0
Public Class Methods
new(*executors)
click to toggle source
Create a periodic executor.
@example Create a PeriodicExecutor
.
Mongo::Cluster::PeriodicExecutor.new(reaper, reaper2)
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 39 def initialize(*executors) @thread = nil @executors = executors end
Public Instance Methods
execute()
click to toggle source
Trigger an execute call on each reaper.
@example Trigger all reapers.
periodic_executor.execute
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 85 def execute @executors.each(&:execute) and true end
flush()
click to toggle source
Execute all pending operations.
@example Execute all pending operations.
periodic_executor.flush
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 97 def flush @executors.each(&:flush) and true end
run!()
click to toggle source
Start the thread.
@example Start the periodic executor's thread.
periodic_executor.run!
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 52 def run! @thread && @thread.alive? ? @thread : start! end
Also aliased as: restart!
stop!(wait=false)
click to toggle source
Stop the executor's thread.
@example Stop the executors's thread.
periodic_executor.stop!
@param [ Boolean ] wait Whether to wait for background threads to
finish running.
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 68 def stop!(wait=false) begin; flush; rescue; end @thread.kill if wait @thread.join end !@thread.alive? end
Private Instance Methods
start!()
click to toggle source
# File lib/mongo/cluster/periodic_executor.rb, line 103 def start! @thread = Thread.new(FREQUENCY) do |i| loop do sleep(i) execute end end end