123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Cluster::PeriodicExecutor Private

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/mongo/cluster/periodic_executor.rb

Overview

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

Since:

  • 2.5.0

Constant Summary

::Mongo::Loggable - Included

PREFIX

Class Method Summary

Instance Attribute Summary

::Mongo::BackgroundThread - Included

Instance Method Summary

::Mongo::BackgroundThread - Included

#run!

Start the background thread.

#stop!

Stop the background thread and wait for to terminate for a reasonable amount of time.

#do_work

Override this method to do the work in the background thread.

#pre_stop

Override this method to perform additional signaling for the background thread to stop.

#start!,
#wait_for_stop

Waits for the thread to die, with a timeout.

::Mongo::Loggable - Included

#log_debug

Convenience method to log debug messages with the standard prefix.

#log_error

Convenience method to log error messages with the standard prefix.

#log_fatal

Convenience method to log fatal messages with the standard prefix.

#log_info

Convenience method to log info messages with the standard prefix.

#log_warn

Convenience method to log warn messages with the standard prefix.

#logger

Get the logger instance.

#_mongo_log_prefix, #format_message

Constructor Details

.new(executors, options = {}) ⇒ PeriodicExecutor

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

[ GitHub ]

  
# File 'lib/mongo/cluster/periodic_executor.rb', line 44

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

Instance Attribute Details

#options (readonly)

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/periodic_executor.rb', line 51

attr_reader :options

Instance Method Details

#do_work

Since:

  • 2.5.0

[ GitHub ]

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

def do_work
  execute
  @stop_semaphore.wait(FREQUENCY)
end

#execute

Trigger an execute call on each reaper.

Examples:

Trigger all reapers.

periodic_executor.execute

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/periodic_executor.rb', line 83

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

#flush

Execute all pending operations.

Examples:

Execute all pending operations.

periodic_executor.flush

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/cluster/periodic_executor.rb', line 96

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

#pre_stop

Since:

  • 2.5.0

[ GitHub ]

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

def pre_stop
  @stop_semaphore.signal
end

#restart!

[ GitHub ]

  
# File 'lib/mongo/cluster/periodic_executor.rb', line 53

alias restart! run!

#stop(final = false)

Since:

  • 2.5.0

[ GitHub ]

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

def stop(final = false)
  super

  begin
    flush
  rescue StandardError
  end

  true
end