Module: Legion::Memory::Consolidator
- Defined in:
- lib/legion/memory/consolidator.rb
Constant Summary collapse
- LOCK_FILE =
File.('~/.legionio/cache/memory_consolidation.lock')
- SESSIONS_DIR =
File.('~/.legion/sessions')
Class Method Summary collapse
- .consolidation_settings ⇒ Object
- .enabled? ⇒ Boolean
- .gate_status ⇒ Object
- .gates_pass? ⇒ Boolean
- .run(force: false) ⇒ Object
Class Method Details
.consolidation_settings ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/legion/memory/consolidator.rb', line 47 def consolidation_settings raw = begin Legion::Settings.dig(:memory, :consolidation) rescue StandardError nil end defaults = { enabled: false, min_hours: 24, min_sessions: 5, scan_interval_minutes: 10, max_index_lines: 200 } raw.is_a?(Hash) ? defaults.merge(raw) : defaults end |
.enabled? ⇒ Boolean
42 43 44 45 |
# File 'lib/legion/memory/consolidator.rb', line 42 def enabled? settings = consolidation_settings settings.fetch(:enabled, false) end |
.gate_status ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/legion/memory/consolidator.rb', line 30 def gate_status { time_gate: time_gate_passes?, session_gate: session_gate_passes?, lock_gate: lock_gate_passes? } end |
.gates_pass? ⇒ Boolean
38 39 40 |
# File 'lib/legion/memory/consolidator.rb', line 38 def gates_pass? time_gate_passes? && session_gate_passes? && lock_gate_passes? end |
.run(force: false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/memory/consolidator.rb', line 12 def run(force: false) return { success: false, reason: :disabled } unless enabled? return { success: false, reason: :gates_failed, details: gate_status } unless force || gates_pass? return { success: false, reason: :locked } unless acquire_lock begin result = consolidate touch_lock publish_to_apollo(result[:insights]) if result[:insights]&.any? { success: true, insights_count: result[:insights]&.length || 0, **result } ensure release_lock end rescue StandardError => e Legion::Logging.error "[Consolidator] failed: #{e.}" if defined?(Legion::Logging) { success: false, reason: :error, error: e. } end |