Class: Sq::Dbsync::LoadAction
- Inherits:
-
Object
- Object
- Sq::Dbsync::LoadAction
- Defined in:
- lib/sq/dbsync/load_action.rb
Overview
An stateful action object representing the transfer of data from a source table to a target. The action can be performed in full using ‘#call`, but control can also be inverted using the `.stages` method, which allows the action to be combined to run efficiently in parallel with other actions.
This is useful because a single load taxes the source system then the target system in sequence, so for maximum efficency a second load should be interleaved to start taxing the source system as soon as the first finishes the extract, rather than waiting for it to also finish the load. This is not possible if the process is fully encapsulated as it is in ‘#call`.
This is an abstract base class, see ‘BatchLoadAction` and `IncrementalLoadAction` for example subclasses.
Direct Known Subclasses
BatchLoadAction, IncrementalLoadAction, RefreshRecentLoadAction
Defined Under Namespace
Classes: NullAction
Constant Summary collapse
- EPOCH =
Date.new(2000, 1, 1).to_time
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #do_prepare ⇒ Object
-
#initialize(target, plan, registry, logger, now = ->{ Time.now.utc }) ⇒ LoadAction
constructor
A new instance of LoadAction.
- #tag ⇒ Object
Constructor Details
#initialize(target, plan, registry, logger, now = ->{ Time.now.utc }) ⇒ LoadAction
Returns a new instance of LoadAction.
32 33 34 35 36 37 38 |
# File 'lib/sq/dbsync/load_action.rb', line 32 def initialize(target, plan, registry, logger, now = ->{ Time.now.utc }) @target = target @plan = OpenStruct.new(plan) @registry = registry @logger = logger @now = now end |
Class Method Details
.stages ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/sq/dbsync/load_action.rb', line 48 def self.stages [ ->(x) { x.do_prepare || NullAction.new }, ->(x) { x.extract_data }, ->(x) { x.load_data }, ->(x) { x.post_load } ] end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'lib/sq/dbsync/load_action.rb', line 44 def call self.class.stages.inject(self) {|x, v| v.call(x) } end |
#do_prepare ⇒ Object
57 58 59 60 61 62 |
# File 'lib/sq/dbsync/load_action.rb', line 57 def do_prepare return unless prepare ensure_target_exists self end |
#tag ⇒ Object
40 41 42 |
# File 'lib/sq/dbsync/load_action.rb', line 40 def tag plan.table_name end |