class Restforce::DB::Runner

Restforce::DB::Runner provides an abstraction for lookup timing during the synchronization process. It provides methods for accessing only recently- modified records within the context of a specific Mapping.

Attributes

after[RW]
before[RW]
last_run[R]

Public Class Methods

new(delay = 0, last_run_time = DB.last_run) click to toggle source

Public: Initialize a new Restforce::DB::Runner.

delay - A Numeric offet to apply to all record lookups. Can be

used to mitigate server timing issues.

last_run_time - A Time indicating the point at which new runs should

begin.
# File lib/restforce/db/runner.rb, line 28
def initialize(delay = 0, last_run_time = DB.last_run)
  @delay = delay
  @last_run = last_run_time
  @record_cache = RecordCache.new
  @timestamp_cache = TimestampCache.new
end

Public Instance Methods

database_instances(cached = true) click to toggle source

Public: Iterate through recently-updated records for the database model record type defined by the current mapping.

cached - A Boolean reflecting whether or not the collection should be

fetched through this runner's RecordCache.

Returns an Enumerator yielding Restforce::DB::Instances::ActiveRecords.

# File lib/restforce/db/runner.rb, line 86
def database_instances(cached = true)
  if cached
    @record_cache.collection(@mapping, :database_record_type, options)
  else
    @mapping.database_record_type.all(options)
  end
end
run(mapping) { |self| ... } click to toggle source

Public: Grant access to recently-updated records for a specific mapping.

mapping - A Restforce::DB::Mapping instance.

Yields self, in the context of the passed mapping. Returns nothing.

# File lib/restforce/db/runner.rb, line 57
def run(mapping)
  @mapping = mapping
  yield self
ensure
  @mapping = nil
end
salesforce_instances(cached = true) click to toggle source

Public: Iterate through recently-updated records for the Salesforce record type defined by the current mapping.

cached - A Boolean reflecting whether or not the collection should be

fetched through this runner's RecordCache.

Returns an Enumerator yielding Restforce::DB::Instances::Salesforces.

# File lib/restforce/db/runner.rb, line 71
def salesforce_instances(cached = true)
  if cached
    @record_cache.collection(@mapping, :salesforce_record_type, options)
  else
    @mapping.salesforce_record_type.all(options)
  end
end
tick!() click to toggle source

Public: Indicate that a new phase of the run is beginning. Updates the before/after timestamp to ensure that new lookups are properly filtered.

Returns the new run Time.

# File lib/restforce/db/runner.rb, line 39
def tick!
  @record_cache.reset
  @timestamp_cache.reset

  run_time = Time.now

  @before = run_time - @delay
  @after = last_run - @delay if @last_run

  @last_run = run_time
end

Private Instance Methods

options() click to toggle source

Internal: Get a Hash of options to apply to record lookups.

Returns a Hash.

# File lib/restforce/db/runner.rb, line 99
def options
  { after: after, before: before }
end