Class: EventMeter::Stores::Rollup::File::ProcessedSidecar

Inherits:
Object
  • Object
show all
Includes:
FileHelpers
Defined in:
lib/event_meter/stores/rollup/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ ProcessedSidecar

Returns a new instance of ProcessedSidecar.



641
642
643
# File 'lib/event_meter/stores/rollup/file.rb', line 641

def initialize(path:)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



639
640
641
# File 'lib/event_meter/stores/rollup/file.rb', line 639

def path
  @path
end

Instance Method Details

#batch_pathsObject



665
666
667
668
669
# File 'lib/event_meter/stores/rollup/file.rb', line 665

def batch_paths
  hash_value(read[BATCHES_KEY]).transform_values do |batch|
    Array(hash_value(batch)["applied_paths"]).map(&:to_s)
  end
end

#deleteObject



682
683
684
685
# File 'lib/event_meter/stores/rollup/file.rb', line 682

def delete
  ::FileUtils.rm_f(path)
  ::FileUtils.rm_f(lock_path)
end

#mark(entry_ids, batch_id:, applied_paths:, timestamp:) ⇒ Object



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/event_meter/stores/rollup/file.rb', line 649

def mark(entry_ids, batch_id:, applied_paths:, timestamp:)
  update do |data|
    data[STREAM_FILE_KEY] ||= stream_file
    processed = hash_value(data[PROCESSED_IDS_KEY])
    entry_ids.each { |id| processed[id.to_s] = timestamp }
    data[PROCESSED_IDS_KEY] = processed

    batches = hash_value(data[BATCHES_KEY])
    batches[batch_id] = {
      "processed_at" => timestamp,
      "applied_paths" => applied_paths
    }
    data[BATCHES_KEY] = batches
  end
end

#old?(before) ⇒ Boolean

Returns:

  • (Boolean)


675
676
677
678
679
680
# File 'lib/event_meter/stores/rollup/file.rb', line 675

def old?(before)
  timestamps = hash_value(read[PROCESSED_IDS_KEY]).values
  return false if timestamps.empty?

  timestamps.all? { |timestamp| processed_entry_old?(timestamp, before) }
end

#processed?(entry_id) ⇒ Boolean

Returns:

  • (Boolean)


645
646
647
# File 'lib/event_meter/stores/rollup/file.rb', line 645

def processed?(entry_id)
  hash_value(read[PROCESSED_IDS_KEY]).key?(entry_id.to_s)
end

#processed_countObject



671
672
673
# File 'lib/event_meter/stores/rollup/file.rb', line 671

def processed_count
  hash_value(read[PROCESSED_IDS_KEY]).length
end