Class: Legion::Audit::ArchiverActor

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/audit/archiver_actor.rb

Constant Summary collapse

INTERVAL_SECONDS =

check every hour; day-of-week guard applies

3600

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/legion/audit/archiver_actor.rb', line 11

def enabled?
  Legion::Audit::Archiver.enabled?
end

.schedule_settingObject



15
16
17
# File 'lib/legion/audit/archiver_actor.rb', line 15

def schedule_setting
  Legion::Settings[:audit]&.dig(:retention, :archive_schedule) || '0 2 * * 0'
end

.scheduled_day_of_weekObject

Parse cron day-of-week (field 5) — returns integer 0..6, 0=Sunday



20
21
22
# File 'lib/legion/audit/archiver_actor.rb', line 20

def scheduled_day_of_week
  schedule_setting.split[4].to_i
end

.scheduled_hourObject

Parse cron hour (field 2)



25
26
27
# File 'lib/legion/audit/archiver_actor.rb', line 25

def scheduled_hour
  schedule_setting.split[1].to_i
end

Instance Method Details

#run_archivalObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/legion/audit/archiver_actor.rb', line 30

def run_archival
  return unless self.class.enabled?

  now = Time.now.utc
  return unless now.wday == self.class.scheduled_day_of_week
  return unless now.hour == self.class.scheduled_hour

  Legion::Logging.info '[Audit::ArchiverActor] starting weekly archival' if defined?(Legion::Logging)

  warm_result = Legion::Audit::Archiver.archive_to_warm
  cold_result = Legion::Audit::Archiver.archive_to_cold

  if Legion::Audit::Archiver.verify_on_archive?
    verify_result = Legion::Audit::Archiver.verify_chain(tier: :warm)
    if !verify_result[:valid] && defined?(Legion::Logging)
      Legion::Logging.error "[Audit::ArchiverActor] chain broken after archival: #{verify_result[:broken_links].count} links"
    end
  end

  return unless defined?(Legion::Logging)

  Legion::Logging.info "[Audit::ArchiverActor] complete warm=#{warm_result[:moved]} cold=#{cold_result[:moved]}"
end