class TapRep::Runner

Kicks off tap-rep process

Attributes

config_filename[R]
state_filename[R]
stream[R]
verbose[R]

Public Class Methods

new(argv, stream: $stderr, config: nil, state: nil) click to toggle source
# File lib/runner.rb, line 19
def initialize(argv, stream: $stderr, config: nil, state: nil)
  @stream = stream
  @config = config
  @state = state
  parser.parse! argv
end

Public Instance Methods

config() click to toggle source
# File lib/runner.rb, line 32
def config
  @config ||= read_json(config_filename)
end
perform() click to toggle source
# File lib/runner.rb, line 26
def perform
  return stream.puts(parser) if config.keys.empty?
  output_schemata
  process_models
end
state() click to toggle source
# File lib/runner.rb, line 36
def state
  @state ||= read_json(state_filename)
end

Private Instance Methods

client() click to toggle source
# File lib/runner.rb, line 54
def client
  @client ||= TapRep::Client.new(
    token: config['token'],
    verbose: verbose,
    state: Concurrent::Hash.new.merge!(state_minus_3_days),
    stream: stream
  )
end
output_schemata() click to toggle source
# File lib/runner.rb, line 42
def output_schemata
  TapRep::Models::Base.subclasses.each do |model|
    client.output model.schema
  end
end
parser() click to toggle source
# File lib/runner.rb, line 86
def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
    opts.on('-c', '--config filename', 'Set config file (json)') do |config|
      @config_filename = config
    end

    opts.on('-s', '--state filename', 'Set state file (json)') do |state|
      @state_filename = state
    end

    opts.on('-v', '--verbose', 'Enables verbose logging to STDERR') do
      @verbose = true
    end
  end
end
process_models() click to toggle source
# File lib/runner.rb, line 48
def process_models
  TapRep::Models::Base.subclasses.each do |model|
    client.process model
  end
end
read_json(filename) click to toggle source
# File lib/runner.rb, line 81
def read_json(filename)
  return JSON.parse(File.read(filename)) if filename
  {}
end
state_minus_3_days() click to toggle source

Per Rep, include a “buffer” when we kick off our process In other words, end_time != session modification time. As a result, just maintaining a high watermark has the potential to miss certain sessions, and the probability of missing sessions increases if there's a big gap between the time of last message in the session and the time it is closed out by an agent (like, on weekends).

For example, if you most recently queried all sessions up until time T1, then set start_time to T1 - 3 days on the next run (and dedupe sessions based on encrypted_id, which is guaranteed to be unique). This should account for sessions that happened over the weekend, etc.

# File lib/runner.rb, line 74
def state_minus_3_days
  return state unless state['sessions']
  state.merge(
    'sessions' => DateTime.parse(state['sessions']).prev_day(3).iso8601
  )
end