Class: Restforce::DB::Worker
- Inherits:
-
Object
- Object
- Restforce::DB::Worker
- Includes:
- FileDaemon, Loggable
- Defined in:
- lib/restforce/db/worker.rb
Overview
Restforce::DB::Worker represents the primary polling loop through which all record synchronization occurs.
Constant Summary collapse
- DEFAULT_INTERVAL =
5
- DEFAULT_DELAY =
1
- GRACEFUL_SHUTDOWN_SIGNALS =
TERM and INT signals should trigger a graceful shutdown.
%w(TERM INT).freeze
- ROTATION_SIGNALS =
HUP and USR1 will reopen all files at their original paths, to accommodate log rotation.
%w(HUP USR1).freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#tracker ⇒ Object
Returns the value of attribute tracker.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Worker
constructor
Public: Initialize a new Restforce::DB::Worker.
-
#start ⇒ Object
Public: Start the polling loop for this Worker.
-
#stop ⇒ Object
Public: Instruct the worker to stop running at the end of the current processing loop.
Methods included from Loggable
Methods included from FileDaemon
Constructor Details
#initialize(options = {}) ⇒ Worker
Public: Initialize a new Restforce::DB::Worker.
options - A Hash of options to configure the worker’s run. Currently
supported are:
interval - The maximum polling loop rest time.
delay - The amount of time by which to offset queries.
config - The path to a client configuration file.
36 37 38 39 |
# File 'lib/restforce/db/worker.rb', line 36 def initialize( = {}) = @interval = .fetch(:interval) { DEFAULT_INTERVAL } end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
27 28 29 |
# File 'lib/restforce/db/worker.rb', line 27 def logger @logger end |
#tracker ⇒ Object
Returns the value of attribute tracker.
27 28 29 |
# File 'lib/restforce/db/worker.rb', line 27 def tracker @tracker end |
Instance Method Details
#start ⇒ Object
Public: Start the polling loop for this Worker. Synchronizes all registered record types between the database and Salesforce, looping indefinitely until processing is interrupted by a signal.
Returns nothing.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/restforce/db/worker.rb', line 46 def start DB.reset DB.configure do |config| config.parse([:config]) config.logger = logger end GRACEFUL_SHUTDOWN_SIGNALS.each { |signal| trap(signal) { stop } } ROTATION_SIGNALS.each { |signal| trap(signal) { Worker.reopen_files } } preload loop do runtime = Benchmark.realtime { perform } sleep(@interval - runtime) if runtime < @interval && !stop? break if stop? end end |
#stop ⇒ Object
Public: Instruct the worker to stop running at the end of the current processing loop.
Returns nothing.
70 71 72 73 |
# File 'lib/restforce/db/worker.rb', line 70 def stop Thread.new { log "Exiting..." } @exit = true end |