Module: RailsNexus::Cleanup

Defined in:
lib/rails_nexus/cleanup.rb

Class Method Summary collapse

Class Method Details

.install_rake_taskObject

Generate a rake task for cleanup. Adds rake rails_nexus:cleanup to your app.



27
28
29
# File 'lib/rails_nexus/cleanup.rb', line 27

def self.install_rake_task
  # This is called automatically by the engine
end

.runObject

Delete exceptions older than the configured retention period. Call this from a cron job, Sidekiq scheduler, or Rails runner.

Usage:

bin/rails runner "RailsNexus::Cleanup.run"

Or schedule with sidekiq-cron / whenever / good_job:

RailsNexus::Cleanup.run


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

def run
  config = RailsNexus.configuration
  return unless config.retention_days.present?

  cutoff = config.retention_days.days.ago
  count = RailsNexus::LoggedException.where("created_at < ?", cutoff).delete_all

  Rails.logger.info("[RailsNexus] Cleaned up #{count} exceptions older than #{config.retention_days} days") if count > 0
  count
end