Class: Textus::Write::RefreshWorker
- Inherits:
-
Object
- Object
- Textus::Write::RefreshWorker
- Defined in:
- lib/textus/write/refresh_worker.rb
Constant Summary collapse
- FETCH_TIMEOUT_SECONDS =
IntakeFetch::FETCH_TIMEOUT_SECONDS
Class Method Summary collapse
Instance Method Summary collapse
-
#call(key) ⇒ Object
call(key) is the primary entry; run is kept as an alias for Orchestrator and RefreshAll which call worker.run(key).
-
#initialize(container:, call:) ⇒ RefreshWorker
constructor
A new instance of RefreshWorker.
- #run(key) ⇒ Object
Constructor Details
#initialize(container:, call:) ⇒ RefreshWorker
Returns a new instance of RefreshWorker.
8 9 10 11 12 13 14 15 |
# File 'lib/textus/write/refresh_worker.rb', line 8 def initialize(container:, call:) @container = container @call = call @manifest = container.manifest @events = container.events @rpc = container.rpc @authorizer = container. end |
Class Method Details
.normalize_action_result(res, format:) ⇒ Object
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/write/refresh_worker.rb', line 35 def self.normalize_action_result(res, format:) res = res.transform_keys(&:to_s) if res.is_a?(Hash) res ||= {} = res["_meta"] body = res["body"] content = res["content"] case format when "markdown" then { meta: || {}, body: body.to_s, content: nil } when "text" then { meta: {}, body: body.to_s, content: nil } when "json", "yaml" if !content.nil? { meta: || {}, body: nil, content: content } elsif !body.nil? { meta: {}, body: body.to_s, content: nil } else raise Textus::UsageError.new("intake for #{format} returned neither content nor body") end else raise Textus::UsageError.new("unknown format #{format.inspect}") end end |
Instance Method Details
#call(key) ⇒ Object
call(key) is the primary entry; run is kept as an alias for Orchestrator and RefreshAll which call worker.run(key).
19 20 21 |
# File 'lib/textus/write/refresh_worker.rb', line 19 def call(key) run(key) end |
#run(key) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/textus/write/refresh_worker.rb', line 23 def run(key) res = @manifest.resolver.resolve(key) mentry = res.entry path = res.path remaining = res.remaining raise UsageError.new("no intake declared for '#{key}'") unless mentry.is_a?(Textus::Manifest::Entry::Intake) before_etag = File.exist?(path) ? Etag.for_file(path) : nil result = fetch_with_events(key, mentry, remaining) persist_and_notify(key, mentry, result, before_etag) end |