Class: Legion::Data::Archival::Policy
- Inherits:
-
Object
- Object
- Legion::Data::Archival::Policy
- Extended by:
- Logging::Helper
- 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
Methods included from Logging::Helper
Constructor Details
#initialize(**opts) ⇒ Policy
Returns a new instance of Policy.
26 27 28 29 30 31 32 |
# File 'lib/legion/data/archival/policy.rb', line 26 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.
24 25 26 |
# File 'lib/legion/data/archival/policy.rb', line 24 def batch_size @batch_size end |
#cold_after_days ⇒ Object (readonly)
Returns the value of attribute cold_after_days.
24 25 26 |
# File 'lib/legion/data/archival/policy.rb', line 24 def cold_after_days @cold_after_days end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
24 25 26 |
# File 'lib/legion/data/archival/policy.rb', line 24 def tables @tables end |
#warm_after_days ⇒ Object (readonly)
Returns the value of attribute warm_after_days.
24 25 26 |
# File 'lib/legion/data/archival/policy.rb', line 24 def warm_after_days @warm_after_days end |
Class Method Details
.from_settings ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/data/archival/policy.rb', line 46 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 handle_exception(e, level: :warn, handled: true, operation: :policy_from_settings) new end |
Instance Method Details
#cold_cutoff ⇒ Object
38 39 40 |
# File 'lib/legion/data/archival/policy.rb', line 38 def cold_cutoff Time.now - (cold_after_days * 86_400) end |
#warm_cutoff ⇒ Object
34 35 36 |
# File 'lib/legion/data/archival/policy.rb', line 34 def warm_cutoff Time.now - (warm_after_days * 86_400) end |