Class: Process::Naf::LogReader

Inherits:
Application
  • Object
show all
Defined in:
app/models/process/naf/log_reader.rb

Constant Summary collapse

UUID_REGEX =
/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#jsonsObject

Returns the value of attribute jsons.



12
13
14
# File 'app/models/process/naf/log_reader.rb', line 12

def jsons
  @jsons
end

#read_from_s3Object

Returns the value of attribute read_from_s3.



12
13
14
# File 'app/models/process/naf/log_reader.rb', line 12

def read_from_s3
  @read_from_s3
end

#s3_log_readerObject

Returns the value of attribute s3_log_reader.



12
13
14
# File 'app/models/process/naf/log_reader.rb', line 12

def s3_log_reader
  @s3_log_reader
end

Instance Method Details

#workObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/process/naf/log_reader.rb', line 16

def work
   @jsons = []
	if @job_id.present?
     job_log_files.each do |file|
       # Use Yajl JSON library to parse the log files, as they contain multiple JSON blocks
       parser = Yajl::Parser.new
       json = get_json_from_log_file(file)
       parser.parse(json) do |log|
         @jsons << log
       end

       sort_jsons
     end

     if jsons.present?
       jsons.each do |elem|
         puts insert_log_line(elem)
       end
     else
       puts 'No logs found'
     end
	elsif @runner_id.present?
     runner_log_files.each do |file|
       # Use Yajl JSON library to parse the log files, as they contain multiple JSON blocks
       parser = Yajl::Parser.new
       json = get_json_from_log_file(file)
       parser.parse(json) do |log|
         log['id'] = get_invocation_id(file.scan(UUID_REGEX).first)
         @jsons << log
       end

       sort_jsons
     end

     if jsons.present?
       jsons.each do |elem|
         puts insert_log_line(elem)
       end
     else
       puts 'No logs found'
     end
	end
end