Class: Textus::Write::FetchWorker
- Inherits:
-
Object
- Object
- Textus::Write::FetchWorker
- Defined in:
- lib/textus/write/fetch_worker.rb
Overview
Internal fetch executor for one quarantine/intake entry. No longer a public verb (ADR 0079 collapsed the ‘fetch` surface): used by `get`’s orchestrator (read-through refresh) and by the ‘tend` sweep.
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 FetchAll which call worker.run(key).
-
#initialize(container:, call:) ⇒ FetchWorker
constructor
A new instance of FetchWorker.
- #run(key) ⇒ Object
Constructor Details
#initialize(container:, call:) ⇒ FetchWorker
Returns a new instance of FetchWorker.
11 12 13 14 15 16 17 |
# File 'lib/textus/write/fetch_worker.rb', line 11 def initialize(container:, call:) @container = container @call = call @manifest = container.manifest @schemas = container.schemas @rpc = container.rpc end |
Class Method Details
.normalize_action_result(res, format:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/textus/write/fetch_worker.rb', line 37 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 FetchAll which call worker.run(key).
21 22 23 |
# File 'lib/textus/write/fetch_worker.rb', line 21 def call(key) run(key) end |
#run(key) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/textus/write/fetch_worker.rb', line 25 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 = @container.file_store.exists?(path) ? @container.file_store.etag(path) : nil result = fetch_with_events(key, mentry, remaining) persist_and_notify(key, mentry, result, before_etag) end |