class DataRetentionJob
Prunes old application data to keep the database from growing unbounded. Runs daily in production.
After the cascade FK migration, execution_histories can be deleted without worrying about orphaned steps or locks. TableLock.reap_stale! runs first to clean up any stale locks before the main pruning pass.
Constants
- BATCH_SIZE
- DEFAULT_RETENTION
- DEFAULT_TIMESTAMP_COLUMN
- KLASSES
-
Explicit table map โ no constantize, no rescue NameError.
- TIMESTAMP_COLUMNS
-
Which column decides โoldโ.
ErrorEventdedupes by message: a recurring failure keeps its original created_at and only bumps last_seen_at, so pruning it by created_at deleted OPEN errors that were still happening - exactly the ones worth keeping. The schemaโs [status, last_seen_at] index points at the right column.
Public Instance Methods
Source
# File app/jobs/data_retention_job.rb, line 37 def perform TableLock.reap_stale! KLASSES.each do |key, klass| prune(key, klass) end prune_solid_queue rescue StandardError => e ErrorEvent.record(catalog: nil, schema: "retention", operation: "data-retention", source_system: "app", error_class: e.class.name, message: e.message) raise end