Class: Restforce::DB::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/db/runner.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delay = 0, last_run_time = DB.last_run) ⇒ Runner

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.


18
19
20
21
# File 'lib/restforce/db/runner.rb', line 18

def initialize(delay = 0, last_run_time = DB.last_run)
  @delay = delay
  @last_run = last_run_time
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



10
11
12
# File 'lib/restforce/db/runner.rb', line 10

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



10
11
12
# File 'lib/restforce/db/runner.rb', line 10

def before
  @before
end

#last_runObject (readonly)

Returns the value of attribute last_run.



10
11
12
# File 'lib/restforce/db/runner.rb', line 10

def last_run
  @last_run
end

Instance Method Details

#database_recordsObject

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

Yields a series of Restforce::DB::Instances::ActiveRecord objects. Returns nothing.



63
64
65
# File 'lib/restforce/db/runner.rb', line 63

def database_records
  @mapping.database_record_type.each(options) { |record| yield record }
end

#run(mapping) ⇒ Object

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.



42
43
44
45
46
47
# File 'lib/restforce/db/runner.rb', line 42

def run(mapping)
  @mapping = mapping
  yield self
ensure
  @mapping = nil
end

#salesforce_recordsObject

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

Yields a series of Restforce::DB::Instances::Salesforce objects. Returns nothing.



54
55
56
# File 'lib/restforce/db/runner.rb', line 54

def salesforce_records
  @mapping.salesforce_record_type.each(options) { |record| yield record }
end

#tick!Object

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.



27
28
29
30
31
32
33
34
# File 'lib/restforce/db/runner.rb', line 27

def tick!
  run_time = Time.now

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

  @last_run = run_time
end