Class: Holistics::ImportChunking

Inherits:
Thor
  • Object
show all
Defined in:
lib/import_chunking.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/import_chunking.rb', line 19

def execute
  one_day = 86_400
  chunk_duration = one_day * options[:chunk_days]

  date_start = Time.parse(options[:range_start])
  date_end = Time.parse(options[:range_end])

  generated_result = []

  current_time = date_start

  while current_time < date_end
    chunk_start = current_time
    chunk_end = current_time + chunk_duration

    generated_result << gen_command(options[:import_id],
                                    chunk_start,
                                    chunk_end < date_end ? chunk_end : date_end)

    current_time += chunk_duration
  end

  puts generated_result.join(" && \\ \n")
end