Class: SolidApm::CleanupService

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_apm/cleanup_service.rb

Constant Summary collapse

DURATION_PATTERN =

Regex to match safe time expressions like “1.week.ago”, “2.months.ago”, etc.

/\A(\d+)\.(second|minute|hour|day|week|month|year)s?\.ago\z/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(older_than: '1.month.ago') ⇒ CleanupService

Returns a new instance of CleanupService.



7
8
9
# File 'lib/solid_apm/cleanup_service.rb', line 7

def initialize(older_than: '1.month.ago')
  @older_than = older_than
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/solid_apm/cleanup_service.rb', line 11

def call
  cutoff_time = parse_time_expression(@older_than)
  deleted_count = Transaction.where(timestamp: ...cutoff_time).destroy_all.size

  {
    cutoff_time: cutoff_time,
    deleted_count: deleted_count,
    older_than: @older_than
  }
end