Class: Textus::Application::Refresh::All

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

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, manifest:, envelope_io:, bus:, store:, authorizer:, hook_context:) ⇒ All

rubocop:disable Metrics/ParameterLists



5
6
7
8
9
10
11
12
13
# File 'lib/textus/application/refresh/all.rb', line 5

def initialize(ctx:, manifest:, envelope_io:, bus:, store:, authorizer:, hook_context:) # rubocop:disable Metrics/ParameterLists
  @ctx          = ctx
  @manifest     = manifest
  @envelope_io  = envelope_io
  @bus          = bus
  @store        = store
  @authorizer   = authorizer
  @hook_context = hook_context
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
42
43
44
45
46
47
48
# File 'lib/textus/application/refresh/all.rb', line 15

def call(prefix: nil, zone: nil)
  worker = Textus::Application::Refresh::Worker.new(
    ctx: @ctx, manifest: @manifest, envelope_io: @envelope_io, bus: @bus,
    store: @store, authorizer: @authorizer, hook_context: @hook_context
  )

  stale_rows = Textus::Application::Reads::Stale.new(manifest: @manifest).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