Class: Textus::Write::RetentionSweep

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/write/retention_sweep.rb

Overview

Applies retention actions reported by Read::Retainable. ‘expire` deletes the leaf through the role gate; `archive` copies it to <root>/archive/<relative-path> first, then deletes. Rows whose zone the caller’s role cannot write surface in ‘failed` rather than aborting.

Instance Method Summary collapse

Constructor Details

#initialize(container:, call:) ⇒ RetentionSweep

Returns a new instance of RetentionSweep.



10
11
12
13
# File 'lib/textus/write/retention_sweep.rb', line 10

def initialize(container:, call:)
  @container = container
  @call      = call
end

Instance Method Details

#call(prefix: nil, zone: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/textus/write/retention_sweep.rb', line 15

def call(prefix: nil, zone: nil)
  rows = Textus::Read::Retainable.new(container: @container, call: @call)
                                 .call(prefix: prefix, zone: zone)
  delete_op = Textus::Write::Delete.new(container: @container, call: @call)
  expired   = []
  archived  = []
  failed    = []

  rows.each do |row|
    key = row["key"]
    begin
      archive_leaf(row) if row["action"] == "archive"
      delete_op.call(key)
      (row["action"] == "archive" ? archived : expired) << key
    rescue Textus::Error => e
      failed << { "key" => key, "error" => e.message }
    end
  end

  {
    "protocol" => Textus::PROTOCOL,
    "ok" => failed.empty?,
    "expired" => expired,
    "archived" => archived,
    "failed" => failed,
  }
end