Class: Textus::Application::Write::RefreshAll::Impl

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

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, caps:, rpc:, writer:, hook_context:) ⇒ Impl

Returns a new instance of Impl.



15
16
17
18
19
20
21
# File 'lib/textus/application/write/refresh_all.rb', line 15

def initialize(ctx:, caps:, rpc:, writer:, hook_context:)
  @ctx          = ctx
  @caps         = caps
  @rpc          = rpc
  @writer       = writer
  @hook_context = hook_context
end

Instance Method Details

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/textus/application/write/refresh_all.rb', line 23

def call(prefix: nil, zone: nil)
  worker = Textus::Application::Write::RefreshWorker::Impl.new(
    ctx: @ctx, caps: @caps, rpc: @rpc, writer: @writer,
    hook_context: @hook_context
  )

  stale_rows = Textus::Application::Read::Stale::Impl.new(caps: @caps).call(prefix: prefix, zone: zone)
  refreshed = []
  failed = []
  skipped = []

  stale_rows.each do |row|
    key = row["key"] || row[:key]
    reason = row["reason"] || row[:reason]
    if reason.to_s.match?(/ttl exceeded|never refreshed/)
      begin
        worker.run(key)
        refreshed << key
      rescue Textus::Error => e
        failed << { "key" => key, "error" => e.message }
      end
    else
      skipped << { "key" => key, "reason" => reason }
    end
  end

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