Class: Mongo::Cluster::PeriodicExecutor Private

Inherits:
Object
  • Object
show all
Includes:
BackgroundThread
Defined in:
lib/mongo/cluster/periodic_executor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A manager that calls #execute on its executors at a regular interval.

Since:

  • 2.5.0

Constant Summary collapse

FREQUENCY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The default time interval for the periodic executor to execute.

Since:

  • 2.5.0

5

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BackgroundThread

#run!, #running?, #stop!

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Constructor Details

#initialize(executors, options = {}) ⇒ PeriodicExecutor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a periodic executor.

Examples:

Create a PeriodicExecutor.

Mongo::Cluster::PeriodicExecutor.new([reaper, reaper2])

Parameters:

  • executors (Array<Object>)

    The executors. Each must respond to #execute and #flush.

  • options (Hash) (defaults to: {})

    The options.

Options Hash (options):

  • :logger (Logger)

    A custom logger to use.

Since:

  • 2.5.0



47
48
49
50
51
52
# File 'lib/mongo/cluster/periodic_executor.rb', line 47

def initialize(executors, options = {})
  @thread = nil
  @executors = executors
  @stop_semaphore = Semaphore.new
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.5.0



54
55
56
# File 'lib/mongo/cluster/periodic_executor.rb', line 54

def options
  @options
end

Instance Method Details

#do_workObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.5.0



58
59
60
61
# File 'lib/mongo/cluster/periodic_executor.rb', line 58

def do_work
  execute
  @stop_semaphore.wait(FREQUENCY)
end

#executeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Trigger an execute call on each reaper.

Examples:

Trigger all reapers.

periodic_executor.execute

Since:

  • 2.5.0



86
87
88
89
# File 'lib/mongo/cluster/periodic_executor.rb', line 86

def execute
  @executors.each(&:execute)
  true
end

#flushObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute all pending operations.

Examples:

Execute all pending operations.

periodic_executor.flush

Since:

  • 2.5.0



99
100
101
102
# File 'lib/mongo/cluster/periodic_executor.rb', line 99

def flush
  @executors.each(&:flush)
  true
end

#pre_stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.5.0



63
64
65
# File 'lib/mongo/cluster/periodic_executor.rb', line 63

def pre_stop
  @stop_semaphore.signal
end

#stop(final = false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.5.0



67
68
69
70
71
72
73
74
75
76
# File 'lib/mongo/cluster/periodic_executor.rb', line 67

def stop(final = false)
  super

  begin
    flush
  rescue
  end

  true
end