Class: Restforce::DB::Runner
- Inherits:
-
Object
- Object
- Restforce::DB::Runner
- Extended by:
- Forwardable
- 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
-
#after ⇒ Object
Returns the value of attribute after.
-
#before ⇒ Object
Returns the value of attribute before.
-
#last_run ⇒ Object
readonly
Returns the value of attribute last_run.
Instance Method Summary collapse
-
#database_instances ⇒ Object
Public: Iterate through recently-updated records for the database model record type defined by the current mapping.
-
#initialize(delay = 0, last_run_time = DB.last_run) ⇒ Runner
constructor
Public: Initialize a new Restforce::DB::Runner.
-
#run(mapping) ⇒ Object
Public: Grant access to recently-updated records for a specific mapping.
-
#salesforce_instances ⇒ Object
Public: Iterate through recently-updated records for the Salesforce record type defined by the current mapping.
-
#tick! ⇒ Object
Public: Indicate that a new phase of the run is beginning.
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.
26 27 28 29 30 31 |
# File 'lib/restforce/db/runner.rb', line 26 def initialize(delay = 0, last_run_time = DB.last_run) @delay = delay @last_run = last_run_time @record_cache = RecordCache.new = TimestampCache.new end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
11 12 13 |
# File 'lib/restforce/db/runner.rb', line 11 def after @after end |
#before ⇒ Object
Returns the value of attribute before.
11 12 13 |
# File 'lib/restforce/db/runner.rb', line 11 def before @before end |
#last_run ⇒ Object (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_instances ⇒ Object
Public: Iterate through recently-updated records for the database model record type defined by the current mapping.
Returns an Enumerator yielding Restforce::DB::Instances::ActiveRecords.
74 75 76 |
# File 'lib/restforce/db/runner.rb', line 74 def database_instances @record_cache.collection(@mapping, :database_record_type, ) 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.
55 56 57 58 59 60 |
# File 'lib/restforce/db/runner.rb', line 55 def run(mapping) @mapping = mapping yield self ensure @mapping = nil end |
#salesforce_instances ⇒ Object
Public: Iterate through recently-updated records for the Salesforce record type defined by the current mapping.
Returns an Enumerator yielding Restforce::DB::Instances::Salesforces.
66 67 68 |
# File 'lib/restforce/db/runner.rb', line 66 def salesforce_instances @record_cache.collection(@mapping, :salesforce_record_type, ) 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.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/restforce/db/runner.rb', line 37 def tick! @record_cache.reset .reset run_time = Time.now @before = run_time - @delay @after = last_run - @delay if @last_run @last_run = run_time end |