Class: SolidObjects::ProcessPruner
- Inherits:
-
Object
- Object
- SolidObjects::ProcessPruner
- Defined in:
- lib/solid_objects/process_pruner.rb,
sig/generated/lib/solid_objects/process_pruner.rbs
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#now ⇒ Object
readonly
Returns the value of attribute now.
Instance Method Summary collapse
-
#initialize(now: SolidObjects.database_adapter.database_now, batch_size: SolidObjects.configuration.prune_batch_size) ⇒ ProcessPruner
constructor
A new instance of ProcessPruner.
- #preview ⇒ Integer
- #prunable ⇒ ActiveRecord::Relation[Process]
- #prune ⇒ Integer
Constructor Details
#initialize(now: SolidObjects.database_adapter.database_now, batch_size: SolidObjects.configuration.prune_batch_size) ⇒ ProcessPruner
Returns a new instance of ProcessPruner.
9 10 11 12 13 14 15 |
# File 'lib/solid_objects/process_pruner.rb', line 9 def initialize( now: SolidObjects.database_adapter.database_now, batch_size: SolidObjects.configuration.prune_batch_size ) @now = now @batch_size = batch_size end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
39 40 41 |
# File 'lib/solid_objects/process_pruner.rb', line 39 def batch_size @batch_size end |
#now ⇒ Object (readonly)
Returns the value of attribute now.
39 40 41 |
# File 'lib/solid_objects/process_pruner.rb', line 39 def now @now end |
Instance Method Details
#preview ⇒ Integer
18 19 20 |
# File 'lib/solid_objects/process_pruner.rb', line 18 def preview prunable.count end |
#prunable ⇒ ActiveRecord::Relation[Process]
42 43 44 45 46 47 |
# File 'lib/solid_objects/process_pruner.rb', line 42 def prunable Process.where( shutdown_state: "stopped", stopped_at: ...(now - SolidObjects.configuration.process_retention) ) end |
#prune ⇒ Integer
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/solid_objects/process_pruner.rb', line 23 def prune deleted = 0 loop do process_ids = prunable.limit(batch_size).pluck(:id) break if process_ids.empty? deleted += Process.where(id: process_ids).delete_all end SolidObjects.instrument(:"processes.pruned", count: deleted) deleted end |