Class: Lhm::Chunker
- Inherits:
-
Object
- Object
- Lhm::Chunker
- Defined in:
- lib/lhm/chunker.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(migration, connection = nil, options = {}) ⇒ Chunker
constructor
Copy from origin to destination in chunks of size ‘stride`.
Methods included from SqlHelper
#annotation, #idx_name, #idx_spec, #version_string
Methods included from Command
Constructor Details
#initialize(migration, connection = nil, options = {}) ⇒ Chunker
Copy from origin to destination in chunks of size ‘stride`. Sleeps for `throttle` milliseconds between each stride.
16 17 18 19 20 21 22 23 |
# File 'lib/lhm/chunker.rb', line 16 def initialize(migration, connection = nil, = {}) @migration = migration @connection = connection @throttler = [:throttler] @start = [:start] || select_start @limit = [:limit] || select_limit @printer = [:printer] || Printer::Percentage.new end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/lhm/chunker.rb', line 12 def connection @connection end |
Instance Method Details
#execute ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lhm/chunker.rb', line 25 def execute return unless @start && @limit @next_to_insert = @start while @next_to_insert < @limit || (@next_to_insert == 1 && @start == 1) stride = @throttler.stride affected_rows = @connection.update(copy(bottom, top(stride))) if @throttler && affected_rows > 0 @throttler.run end @printer.notify(bottom, @limit) @next_to_insert = top(stride) + 1 end @printer.end end |