Class: Trainspotter::Ingest::Processor

Inherits:
Struct
  • Object
show all
Defined in:
app/jobs/trainspotter/ingest/processor.rb

Constant Summary collapse

DEFAULT_CHUNK_SIZE =
10_000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chunk_sizeObject

Returns the value of attribute chunk_size

Returns:

  • the current value of chunk_size



3
4
5
# File 'app/jobs/trainspotter/ingest/processor.rb', line 3

def chunk_size
  @chunk_size
end

#log_pathObject

Returns the value of attribute log_path

Returns:

  • the current value of log_path



3
4
5
# File 'app/jobs/trainspotter/ingest/processor.rb', line 3

def log_path
  @log_path
end

#session_builderObject

Returns the value of attribute session_builder

Returns:

  • the current value of session_builder



3
4
5
# File 'app/jobs/trainspotter/ingest/processor.rb', line 3

def session_builder
  @session_builder
end

Class Method Details

.call(log_paths, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ Object



6
7
8
9
10
11
12
13
# File 'app/jobs/trainspotter/ingest/processor.rb', line 6

def self.call(log_paths, chunk_size: DEFAULT_CHUNK_SIZE)
  session_builder = Ingest::SessionBuilder.new

  log_paths.each do |log_path|
    next unless File.exist?(log_path)
    new(log_path:, session_builder:, chunk_size:).call
  end
end

Instance Method Details

#callObject



15
16
17
18
19
20
# File 'app/jobs/trainspotter/ingest/processor.rb', line 15

def call
  if position = unread_position
    process_chunk(position)
    expire_stale_sessions
  end
end