Class: Fosm::DataRetentionPurgeJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Fosm::DataRetentionPurgeJob
- Defined in:
- app/jobs/fosm/data_retention_purge_job.rb
Overview
Safely purges FOSM records that have exceeded the configured data retention window. Designed to be triggered from the Data Archival admin UI.
Safety guarantees
-
Re-checks archival eligibility of the model class on entry.
-
Re-checks
Fosm::DataRetention.safe_to_purge?per record inside the job — the controller’s pre-check is advisory only; the retention window or record state could change between the UI request and job execution. -
Missing records are silently skipped (already purged — idempotent).
-
Records within the retention window are NEVER deleted, even when explicitly enqueued — this is the absolute last line of defence.
-
fosm_transition_logsrows are NOT deleted. The audit trail is preserved forever for compliance purposes. -
Errors on individual records are logged, not re-raised, so a bulk job continues processing the remaining records.
-
Unknown or non-eligible model class names abort immediately without side-effects.
Usage
# Single record
Fosm::DataRetentionPurgeJob.perform_later(
model_class_name: "Fosm::FaasAccount",
record_id: "42",
purged_by_label: current_user.email
)
# Bulk — purges every eligible record for the model
Fosm::DataRetentionPurgeJob.perform_later(
model_class_name: "Fosm::FaasAccount",
bulk: true,
purged_by_label: current_user.email
)
Instance Method Summary collapse
Instance Method Details
#perform(model_class_name:, record_id: nil, bulk: false, purged_by_label: "system") ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/jobs/fosm/data_retention_purge_job.rb', line 43 def perform(model_class_name:, record_id: nil, bulk: false, purged_by_label: "system") model_class = resolve_model_class(model_class_name) return unless model_class unless Fosm::DataRetention.archival_eligible?(model_class) log_warn "#{model_class_name} is not archival-eligible. Purge aborted." return end if bulk purge_all_expired(model_class, purged_by_label) elsif record_id.present? purge_single(model_class, record_id.to_s, purged_by_label) else log_warn "Neither bulk: true nor record_id provided. Nothing to purge." end end |