Class: KMDB::Jobs::ParseFile

Inherits:
Locked
  • Object
show all
Defined in:
lib/kmdb/jobs/parse_file.rb

Overview

Reads a file from disk, queues jobs for chunks of events.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ParseFile

Returns a new instance of ParseFile.



21
22
23
# File 'lib/kmdb/jobs/parse_file.rb', line 21

def initialize(file)
  @file = file
end

Class Method Details

.perform(id) ⇒ Object



17
18
19
# File 'lib/kmdb/jobs/parse_file.rb', line 17

def self.perform(id)
  new(JsonFile.new(id)).work
end

Instance Method Details

#workObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kmdb/jobs/parse_file.rb', line 25

def work
  current_batch = []
  current_stamp = nil

  _each_event_in_file(@file) do |event|
    if event.nil?
      _save_batch(current_batch)
      true
    elsif current_batch.length > _batch_size && event['_t'] != current_stamp
      _save_batch(current_batch)
      current_batch << event
      true
    else
      current_batch << event
      false
    end
  end
end