Class: Restforce::DB::Worker
- Inherits:
-
Object
- Object
- Restforce::DB::Worker
- Includes:
- FileDaemon
- 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
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 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.
config - The path to a client configuration file.
verbose - Display command line output? Defaults to false.
25 26 27 28 29 30 31 32 |
# File 'lib/restforce/db/worker.rb', line 25 def initialize( = {}) @verbose = .fetch(:verbose) { false } @interval = .fetch(:interval) { DEFAULT_INTERVAL } @delay = .fetch(:delay) { DEFAULT_DELAY } DB.reset DB.configure { |config| config.parse([:config]) } end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
16 17 18 |
# File 'lib/restforce/db/worker.rb', line 16 def logger @logger end |
#tracker ⇒ Object
Returns the value of attribute tracker.
16 17 18 |
# File 'lib/restforce/db/worker.rb', line 16 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.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/restforce/db/worker.rb', line 39 def start DB.configure { |config| config.logger = logger } trap_signals 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.
56 57 58 59 |
# File 'lib/restforce/db/worker.rb', line 56 def stop Thread.new { log "Exiting..." } @exit = true end |