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
Attributes
options[R]
Public Class Methods
new(executors = [], options = {})
click to toggle source
Create a periodic executor.
@example Create a PeriodicExecutor
.
Mongo::Cluster::PeriodicExecutor.new([reaper, reaper2])
@param [ Hash ] options The options.
@option options [ Logger
] :logger A custom logger to use.
@api private
@since 2.5.0
# File lib/mongo/cluster/periodic_executor.rb, line 43 def initialize(executors = [], options = {}) @thread = nil @executors = executors @stop_semaphore = Semaphore.new @options = options end
Public Instance Methods
do_work()
click to toggle source
# File lib/mongo/cluster/periodic_executor.rb, line 54 def do_work execute @stop_semaphore.wait(FREQUENCY) end
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 82 def execute @executors.each(&:execute) 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 95 def flush @executors.each(&:flush) true end
pre_stop()
click to toggle source
# File lib/mongo/cluster/periodic_executor.rb, line 59 def pre_stop @stop_semaphore.signal end
stop(final = false)
click to toggle source
Calls superclass method
# File lib/mongo/cluster/periodic_executor.rb, line 63 def stop(final = false) super begin flush rescue end true end