Class: TimeBucketStream::Quarantine

Inherits:
Object
  • Object
show all
Defined in:
lib/time_bucket_stream/quarantine.rb

Constant Summary collapse

DEFAULT_RETENTION =
7 * 24 * 60 * 60
TIMESTAMP_PATTERN =
/\.q-(\d{20})-\d+-[0-9a-f]+\.jsonl\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, clock: Time, retention: DEFAULT_RETENTION) ⇒ Quarantine

Returns a new instance of Quarantine.



25
26
27
28
29
# File 'lib/time_bucket_stream/quarantine.rb', line 25

def initialize(path:, clock: Time, retention: DEFAULT_RETENTION)
  @paths = Paths.new(path: path)
  @clock = clock
  @retention = self.class.normalize_retention(retention)
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



12
13
14
# File 'lib/time_bucket_stream/quarantine.rb', line 12

def paths
  @paths
end

#retentionObject (readonly)

Returns the value of attribute retention.



12
13
14
# File 'lib/time_bucket_stream/quarantine.rb', line 12

def retention
  @retention
end

Class Method Details

.normalize_retention(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/time_bucket_stream/quarantine.rb', line 14

def self.normalize_retention(value)
  return nil if value.nil?

  seconds = Integer(value)
  return seconds if seconds >= 0

  raise ArgumentError
rescue ArgumentError, TypeError, RangeError
  raise ArgumentError, "quarantine_retention must be nil or a non-negative number of seconds"
end

Instance Method Details

#cleanupObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/time_bucket_stream/quarantine.rb', line 31

def cleanup
  return unless retention

  cutoff = current_time.utc - retention

  quarantine_log_names.each do |log_name|
    delete_pair(log_name) if expired_log?(log_name, cutoff)
  end

  .each do ||
    () if expired_metadata?(, cutoff)
  end
rescue SystemCallError, IOError, JSON::ParserError
  nil
end