Class: Legion::Data::Archival::Policy
- Inherits:
-
Object
- Object
- Legion::Data::Archival::Policy
- Defined in:
- lib/legion/data/archival/policy.rb
Constant Summary collapse
- DEFAULTS =
{ warm_after_days: 7, cold_after_days: 90, batch_size: 1000, tables: %w[tasks metering_records].freeze }.freeze
- DATE_COLUMN_OVERRIDES =
Per-table date column overrides. The Retention module defaults to :created_at, but legacy tables (like tasks) use :created. Migration 051 may add a created_at column/alias for tasks (implementation varies by adapter); this map forces use of :created so behavior is consistent across legacy schemas and adapters.
{ 'tasks' => :created }.freeze
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#cold_after_days ⇒ Object
readonly
Returns the value of attribute cold_after_days.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#warm_after_days ⇒ Object
readonly
Returns the value of attribute warm_after_days.
Class Method Summary collapse
Instance Method Summary collapse
- #cold_cutoff ⇒ Object
-
#initialize(**opts) ⇒ Policy
constructor
A new instance of Policy.
- #warm_cutoff ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Policy
Returns a new instance of Policy.
24 25 26 27 28 29 30 |
# File 'lib/legion/data/archival/policy.rb', line 24 def initialize(**opts) config = DEFAULTS.merge(opts) @warm_after_days = config[:warm_after_days] @cold_after_days = config[:cold_after_days] @batch_size = config[:batch_size] @tables = config[:tables] end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
22 23 24 |
# File 'lib/legion/data/archival/policy.rb', line 22 def batch_size @batch_size end |
#cold_after_days ⇒ Object (readonly)
Returns the value of attribute cold_after_days.
22 23 24 |
# File 'lib/legion/data/archival/policy.rb', line 22 def cold_after_days @cold_after_days end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
22 23 24 |
# File 'lib/legion/data/archival/policy.rb', line 22 def tables @tables end |
#warm_after_days ⇒ Object (readonly)
Returns the value of attribute warm_after_days.
22 23 24 |
# File 'lib/legion/data/archival/policy.rb', line 22 def warm_after_days @warm_after_days end |
Class Method Details
.from_settings ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/data/archival/policy.rb', line 40 def self.from_settings return new unless defined?(Legion::Settings) data_settings = Legion::Settings[:data] archival = data_settings.is_a?(Hash) ? data_settings[:archival] : nil return new unless archival.is_a?(Hash) new(**archival.slice(:warm_after_days, :cold_after_days, :batch_size, :tables)) rescue StandardError => e Legion::Logging.warn("Policy.from_settings failed: #{e.}") if defined?(Legion::Logging) new end |
Instance Method Details
#cold_cutoff ⇒ Object
36 37 38 |
# File 'lib/legion/data/archival/policy.rb', line 36 def cold_cutoff Time.now - (cold_after_days * 86_400) end |
#warm_cutoff ⇒ Object
32 33 34 |
# File 'lib/legion/data/archival/policy.rb', line 32 def warm_cutoff Time.now - (warm_after_days * 86_400) end |