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
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.
16 17 18 19 20 21 22 |
# File 'lib/legion/data/archival/policy.rb', line 16 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.
14 15 16 |
# File 'lib/legion/data/archival/policy.rb', line 14 def batch_size @batch_size end |
#cold_after_days ⇒ Object (readonly)
Returns the value of attribute cold_after_days.
14 15 16 |
# File 'lib/legion/data/archival/policy.rb', line 14 def cold_after_days @cold_after_days end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
14 15 16 |
# File 'lib/legion/data/archival/policy.rb', line 14 def tables @tables end |
#warm_after_days ⇒ Object (readonly)
Returns the value of attribute warm_after_days.
14 15 16 |
# File 'lib/legion/data/archival/policy.rb', line 14 def warm_after_days @warm_after_days end |
Class Method Details
.from_settings ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/legion/data/archival/policy.rb', line 32 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
28 29 30 |
# File 'lib/legion/data/archival/policy.rb', line 28 def cold_cutoff Time.now - (cold_after_days * 86_400) end |
#warm_cutoff ⇒ Object
24 25 26 |
# File 'lib/legion/data/archival/policy.rb', line 24 def warm_cutoff Time.now - (warm_after_days * 86_400) end |